chore: formatting

This commit is contained in:
2025-05-06 14:37:07 +02:00
parent ae373b3528
commit ca1a50551e
9 changed files with 47 additions and 50 deletions
-4
View File
@@ -1,15 +1,11 @@
<script setup lang="ts">
import { useUserStore } from "~/store/user.store";
import { useLobbyStore } from "./store/lobby.store";
import { useConceptStore } from "./store/concepts.store";
import PageHeader from "./components/pageHeader.vue";
const userStore = useUserStore();
const lobbyStore = useLobbyStore();
const conceptStore = useConceptStore()
void userStore.whoami();
void conceptStore.fetchConceptTypes();
void conceptStore.fetchConceptList()
void lobbyStore.fetchGames();
+4 -5
View File
@@ -25,18 +25,18 @@ export const handlers = {
void gameStore.getCurrentWord(gameStore.game.id);
}
},
delete: (event: GameDeleteEvent) => {
delete: async (event: GameDeleteEvent) => {
const gameStore = useGameStore();
gameStore.game = {} as GameResponseDTO;
alert("Game deleted");
navigateTo("/");
await navigateTo("/");
},
message: (event: GameMessageEvent) => {
const gameStore = useGameStore();
gameStore.game.messages.push(event.message);
if (!event.message.authorId) {
const player = gameStore.game.players.find(
(p) => p.userId == event.message.value
(p) => p.userId == event.message.value,
);
if (player) {
player.score++;
@@ -46,7 +46,7 @@ export const handlers = {
deleteMessage: (event: GameMessageDeleteEvent) => {
const gameStore = useGameStore();
const index = gameStore.game.messages.findIndex(
(m) => m.id == event.messageId
(m) => m.id == event.messageId,
);
gameStore.game.messages.splice(index, 1);
},
@@ -54,7 +54,6 @@ export const handlers = {
const gameStore = useGameStore();
const userStore = useUserStore();
gameStore.game.players.forEach((p) => (p.hasGuessed = false));
gameStore.game.currentConcepts = [];
gameStore.game.messages = [];
gameStore.game.currentPlayer = event.currentPlayer;
if (userStore.self && userStore.self.id == event.currentPlayer.userId) {
+1 -1
View File
@@ -27,7 +27,7 @@ export const handlers = {
leavegame: (event: LobbyLeaveEvent) => {
const lobbyStore = useLobbyStore();
const playerIndex = lobbyStore.games[event.game.id].players.findIndex(
(p) => p.userId == event.player.userId
(p) => p.userId == event.player.userId,
);
lobbyStore.games[event.game.id].players.splice(playerIndex, 1);
},
+5 -7
View File
@@ -7,27 +7,25 @@ import {
WordEnableEvent,
} from "../events/word.events";
export const handlers = {
create: (event: WordCreateEvent) => {
const wordStore = useWordStore();
wordStore.words[event.word.id] = event.word
wordStore.words[event.word.id] = event.word;
},
edit: (event: WordEditEvent) => {
const wordStore = useWordStore();
wordStore.words[event.word.id].value = event.word.value
wordStore.words[event.word.id].value = event.word.value;
},
delete: (event: WordDeleteEvent) => {
const wordStore = useWordStore();
delete wordStore.words[event.id]
delete wordStore.words[event.id];
},
enable: (event: WordEnableEvent) => {
const wordStore = useWordStore();
wordStore.words[event.id].enabled = true
wordStore.words[event.id].enabled = true;
},
disable: (event: WordDisableEvent) => {
const wordStore = useWordStore();
wordStore.words[event.id].enabled = false
wordStore.words[event.id].enabled = false;
},
};
+12 -11
View File
@@ -1,6 +1,7 @@
import { defineStore } from "pinia";
import { subscribe } from "~/netcode";
import { GameResponseDTO } from "~/netcode/events/dto/gameresponse.dto";
import type { ConceptEvent } from "~/netcode/events/events";
import { handlers } from "~/netcode/handlers/game.handler";
export const useGameStore = defineStore("game", {
@@ -10,18 +11,18 @@ export const useGameStore = defineStore("game", {
eventSource: null as null | EventSource,
}),
actions: {
async subscribe(id: number) {
subscribe(id: number) {
this.eventSource = subscribe(`/games/${id}/subscribe`);
this.eventSource.addEventListener("message", async (message) => {
const data = JSON.parse(message.data);
const type = data.type as string;
this.eventSource.addEventListener("message", (message) => {
const data = JSON.parse(message.data as string) as ConceptEvent;
const type = data.type;
console.log(type);
if (type in handlers) {
handlers[type as keyof typeof handlers](data);
}
});
},
async close() {
close() {
this.eventSource?.close();
},
async fetchGame(id: number) {
@@ -31,7 +32,7 @@ export const useGameStore = defineStore("game", {
{
credentials: "include",
immediate: true,
}
},
);
if (data.data.value) {
this.game = data.data.value;
@@ -45,7 +46,7 @@ export const useGameStore = defineStore("game", {
{
method: "POST",
credentials: "include",
}
},
);
},
async startGame(id: number) {
@@ -55,7 +56,7 @@ export const useGameStore = defineStore("game", {
{
method: "POST",
credentials: "include",
}
},
);
},
async deleteGame(id: number) {
@@ -65,7 +66,7 @@ export const useGameStore = defineStore("game", {
{
method: "DELETE",
credentials: "include",
}
},
);
},
async getCurrentWord(id: number) {
@@ -74,7 +75,7 @@ export const useGameStore = defineStore("game", {
config.public.endpoint + `/games/` + id + "/currentWord",
{
credentials: "include",
}
},
);
if (data) {
this.currentWord = data;
@@ -92,7 +93,7 @@ export const useGameStore = defineStore("game", {
value: message,
},
credentials: "include",
}
},
);
},
},
+8 -7
View File
@@ -1,6 +1,7 @@
import { defineStore } from "pinia";
import { subscribe } from "~/netcode";
import type { GameResponseDTO } from "~/netcode/events/dto/gameresponse.dto";
import type { ConceptEvent } from "~/netcode/events/events";
import { handlers } from "~/netcode/handlers/lobby.handler";
export const useLobbyStore = defineStore("lobby", {
@@ -9,17 +10,17 @@ export const useLobbyStore = defineStore("lobby", {
eventSource: null as null | EventSource,
}),
actions: {
async subscribe() {
subscribe() {
this.eventSource = subscribe(`/games/subscribe`);
this.eventSource.addEventListener("message", async (message) => {
const data = JSON.parse(message.data);
const type = data.type as string;
this.eventSource.addEventListener("message", (message) => {
const data = JSON.parse(message.data as string) as ConceptEvent;
const type = data.type;
if (type in handlers) {
handlers[type as keyof typeof handlers](data);
}
});
},
async close() {
close() {
this.eventSource?.close();
},
async fetchGames() {
@@ -29,7 +30,7 @@ export const useLobbyStore = defineStore("lobby", {
{
credentials: "include",
immediate: true,
}
},
);
if (data.data.value) {
for (const game of data.data.value) {
@@ -46,7 +47,7 @@ export const useLobbyStore = defineStore("lobby", {
{
method: "POST",
credentials: "include",
}
},
);
// this.games[data.id] = data;
return data;
+5 -4
View File
@@ -1,5 +1,6 @@
import { defineStore } from "pinia";
import { UserResponseDTO } from "~/netcode/events/dto/userresponse.dto";
import { type FetchContext } from "ofetch";
export const useUserStore = defineStore("user", {
state: () => ({
@@ -18,7 +19,7 @@ export const useUserStore = defineStore("user", {
{
credentials: "include",
immediate: true,
}
},
);
if (data.data.value) {
this.users[data.data.value.id] = data.data.value;
@@ -33,15 +34,15 @@ export const useUserStore = defineStore("user", {
credentials: "include",
server: false,
immediate: true,
onResponse: (data) => {
if (data.response.ok) {
onResponse: (data: FetchContext<UserResponseDTO>) => {
if (data.response && data.response.ok && data.response._data) {
this.self = data.response._data;
}
this.has_contacted = true;
},
lazy: true,
}
},
);
return req;
},
+11 -10
View File
@@ -1,6 +1,7 @@
import { defineStore } from "pinia";
import { subscribe } from "~/netcode";
import { WordResponseDTO } from "~/netcode/events/dto/wordresponse.dto";
import type { ConceptEvent } from "~/netcode/events/events";
import { handlers } from "~/netcode/handlers/word.handler";
export const useWordStore = defineStore("word", {
@@ -9,17 +10,17 @@ export const useWordStore = defineStore("word", {
eventSource: null as null | EventSource,
}),
actions: {
async subscribe() {
subscribe() {
this.eventSource = subscribe(`/words/subscribe`);
this.eventSource.addEventListener("message", async (message) => {
const data = JSON.parse(message.data);
const type = data.type as string;
this.eventSource.addEventListener("message", (message) => {
const data = JSON.parse(message.data as string) as ConceptEvent;
const type = data.type;
if (type in handlers) {
handlers[type as keyof typeof handlers](data);
}
});
},
async close() {
close() {
this.eventSource?.close();
},
async fetchWordList() {
@@ -28,7 +29,7 @@ export const useWordStore = defineStore("word", {
config.public.endpoint + `/words/all`,
{
credentials: "include",
}
},
);
if (data.data.value && !data.error.value) {
for (const word of data.data.value) {
@@ -44,7 +45,7 @@ export const useWordStore = defineStore("word", {
{
credentials: "include",
method: "PUT",
}
},
);
// word.enabled = true;
// return data;
@@ -56,7 +57,7 @@ export const useWordStore = defineStore("word", {
{
credentials: "include",
method: "PUT",
}
},
);
// word.enabled = false;
// return data;
@@ -70,7 +71,7 @@ export const useWordStore = defineStore("word", {
credentials: "include",
body: { value },
method: "POST",
}
},
);
// this.words[data.id] = data;
// return data;
@@ -82,7 +83,7 @@ export const useWordStore = defineStore("word", {
{
credentials: "include",
method: "DELETE",
}
},
);
// delete this.words[word.id];
},