Skip to content

Commit

Permalink
Prevent users from clicking the button twice
Browse files Browse the repository at this point in the history
  • Loading branch information
spider-hand committed May 21, 2023
1 parent 87d8cc9 commit c8f7f39
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
2 changes: 2 additions & 0 deletions src/components/Home/CreateGameForm.vue
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,8 @@ export default defineComponent({
const startMultiplayerGame = async (): Promise<void> => {
try {
store.dispatch("onClickStartButtonAction");
if (store.state.gameSettings.isOwner) {
let randomNumber: number;
let snapshot: DataSnapshot;
Expand Down
4 changes: 1 addition & 3 deletions src/components/Home/CreateRoomDialog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,7 @@
</div>
<div :class="$style['create-room-dialog__form']">
<div>
<span :class="$style['create-room-dialog__text']"
>Are you an owner?</span
>
<span :class="$style['create-room-dialog__text']">Are you a host?</span>
</div>
<Space />
<Switch :ans="isOwner" @onChangeValue="onChangeIsOwner" />
Expand Down
10 changes: 10 additions & 0 deletions src/store/modules/gameSettingsStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export interface GameSettingsState {
playerId: string;
isOwner: boolean;
roomNumber: string;
isStartingGame: boolean;
geoJSON: any;
}

Expand All @@ -23,6 +24,7 @@ const getDefaultState = (): GameSettingsState => ({
playerId: "",
isOwner: true,
roomNumber: "",
isStartingGame: false,
geoJSON: null,
});

Expand All @@ -36,6 +38,8 @@ export const gameSettingsStore = {
return idx >= 0 ? MAP_OPTIONS[idx].text : "";
},
isReadyForMultiplayerGame(state: GameSettingsState) {
if (state.isStartingGame) return false;

if (state.isOwner) {
return state.playerName !== "";
} else {
Expand Down Expand Up @@ -75,6 +79,9 @@ export const gameSettingsStore = {
changeRoomNumber(state: GameSettingsState, value: string) {
state.roomNumber = value;
},
clickStartButton(state: GameSettingsState) {
state.isStartingGame = true;
},
fetchGeoJSON(state: GameSettingsState, value: any) {
state.geoJSON = value;
},
Expand Down Expand Up @@ -107,6 +114,9 @@ export const gameSettingsStore = {
changeRoomNumberAction({ commit }: any, payload: any) {
commit("changeRoomNumber", payload.roomNumber);
},
onClickStartButtonAction({ commit }: any) {
commit("clickStartButton");
},
async fetchGeoJSONAction({ commit }: any, payload: any) {
try {
const resp = await axios.get(
Expand Down

0 comments on commit c8f7f39

Please sign in to comment.