fet : add game delete
This commit is contained in:
@@ -17,9 +17,13 @@ export const handlers = {
|
|||||||
},
|
},
|
||||||
start: (event: GameStartEvent) => {
|
start: (event: GameStartEvent) => {
|
||||||
const gameStore = useGameStore();
|
const gameStore = useGameStore();
|
||||||
|
const userStore = useUserStore();
|
||||||
gameStore.game.started = true;
|
gameStore.game.started = true;
|
||||||
gameStore.game.currentPlayer = event.currentPlayer;
|
gameStore.game.currentPlayer = event.currentPlayer;
|
||||||
gameStore.currentWord = null;
|
gameStore.currentWord = null;
|
||||||
|
if (userStore.self && userStore.self.id == event.currentPlayer.userId) {
|
||||||
|
void gameStore.getCurrentWord(gameStore.game.id);
|
||||||
|
}
|
||||||
},
|
},
|
||||||
delete: (event: GameDeleteEvent) => {
|
delete: (event: GameDeleteEvent) => {
|
||||||
const gameStore = useGameStore();
|
const gameStore = useGameStore();
|
||||||
|
|||||||
+22
-12
@@ -30,6 +30,10 @@ function joinGame() {
|
|||||||
gameStore.joinGame(gameId);
|
gameStore.joinGame(gameId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function deleteGame() {
|
||||||
|
gameStore.deleteGame(gameId);
|
||||||
|
}
|
||||||
|
|
||||||
const isCurrentTurn = computed(
|
const isCurrentTurn = computed(
|
||||||
() =>
|
() =>
|
||||||
userStore.self && userStore.self?.id == game.value?.currentPlayer?.userId
|
userStore.self && userStore.self?.id == game.value?.currentPlayer?.userId
|
||||||
@@ -95,18 +99,24 @@ const selfPlayer = computed(() =>
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
{{ game }}
|
{{ game }}
|
||||||
<input
|
<template v-if="userStore.self">
|
||||||
type="button"
|
<template v-if="!game.started">
|
||||||
v-if="userStore.self && !game.started && game.ownerId == userStore.self.id"
|
<input
|
||||||
value="start"
|
type="button"
|
||||||
@click="startGame"
|
v-if="game.ownerId == userStore.self.id"
|
||||||
/>
|
value="start"
|
||||||
<input
|
@click="startGame"
|
||||||
type="button"
|
/>
|
||||||
v-if="userStore.self && !game.started && !selfPlayer"
|
<input type="button" v-if="!selfPlayer" value="join" @click="joinGame" />
|
||||||
value="join"
|
</template>
|
||||||
@click="joinGame"
|
<input
|
||||||
/>
|
v-if="game.ownerId == userStore.self.id"
|
||||||
|
type="button"
|
||||||
|
value="delete"
|
||||||
|
@click="deleteGame"
|
||||||
|
/>
|
||||||
|
</template>
|
||||||
|
|
||||||
<div>
|
<div>
|
||||||
Messages
|
Messages
|
||||||
<span v-for="message in game.messages" :key="message.id">
|
<span v-for="message in game.messages" :key="message.id">
|
||||||
|
|||||||
@@ -58,6 +58,16 @@ export const useGameStore = defineStore("game", {
|
|||||||
}
|
}
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
async deleteGame(id: number) {
|
||||||
|
const config = useRuntimeConfig();
|
||||||
|
const data = await $fetch<GameResponseDTO>(
|
||||||
|
config.public.endpoint + `/games/` + id,
|
||||||
|
{
|
||||||
|
method: "DELETE",
|
||||||
|
credentials: "include",
|
||||||
|
}
|
||||||
|
);
|
||||||
|
},
|
||||||
async getCurrentWord(id: number) {
|
async getCurrentWord(id: number) {
|
||||||
const config = useRuntimeConfig();
|
const config = useRuntimeConfig();
|
||||||
const data = await $fetch<string>(
|
const data = await $fetch<string>(
|
||||||
|
|||||||
Reference in New Issue
Block a user