Template
25 lines
830 B
TypeScript
25 lines
830 B
TypeScript
import { defineStore } from "pinia";
|
|
import type { GameResponseDTO } from "~/netcode/events/dto/gameresponse.dto";
|
|
import { UserResponseDTO } from "~/netcode/events/dto/userresponse.dto";
|
|
|
|
export const useLobbyStore = defineStore("lobby", {
|
|
state: () => ({
|
|
games: {} as Record<string, GameResponseDTO,
|
|
}),
|
|
actions: {
|
|
async fetchGames() {
|
|
const config = useRuntimeConfig();
|
|
const data = await useFetch<GameResponseDTO[]>(config.public.endpoint + `/users/` + id, {
|
|
credentials: "include",
|
|
immediate: true
|
|
})
|
|
if(data.data.value){
|
|
for(const game of data.data.value){
|
|
this.games[game.id] = game
|
|
}
|
|
}
|
|
|
|
return data.data
|
|
},
|
|
},
|
|
}); |