feat(ui): FRO-34 Lobby (#21)
Started with Lobby Component Co-authored-by: LQ63 <lkhermann@web.de> Co-authored-by: Janis <janis-e@gmx.de> Reviewed-on: #21 Reviewed-by: Janis <janis-e@gmx.de> Co-authored-by: lq64 <lq@blackhole.local> Co-committed-by: lq64 <lq@blackhole.local>
This commit is contained in:
@@ -2,6 +2,7 @@ import { defineStore } from 'pinia'
|
||||
import {ref, type Ref} from 'vue'
|
||||
import type {GameInfo, LobbyInfo, TieInfo, TrumpInfo, WonInfo} from "@/types/GameTypes.ts";
|
||||
import axios from "axios";
|
||||
import {initWebSocket} from "@/services/ws.ts";
|
||||
|
||||
const api = window?.__RUNTIME_CONFIG__?.API_URL;
|
||||
|
||||
@@ -14,8 +15,8 @@ export const useIngame = defineStore('ingame', () => {
|
||||
data.value = newData;
|
||||
}
|
||||
|
||||
function requestGame(gameId: string) {
|
||||
axios.get(`${api}/status/${gameId}`, {withCredentials: true}).then((response) => {
|
||||
async function requestGame(gameId: string) {
|
||||
await axios.get(`${api}/status/${gameId}`, {withCredentials: true}).then((response) => {
|
||||
setIngame(response.data.state, response.data.data);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -18,13 +18,15 @@ export const useUserInfo = defineStore('userInfo', () => {
|
||||
gameId.value = id;
|
||||
}
|
||||
|
||||
function requestState() {
|
||||
axios.get(`${api}/status`, {withCredentials: true}).then((response) => {
|
||||
async function requestState() {
|
||||
await axios.get(`${api}/status`, {withCredentials: true}).then((response) => {
|
||||
console.log("STATUS DATA:" + response.data.status + response.data.inGame)
|
||||
username.value = response.data.username;
|
||||
if (response.data.ingame) {
|
||||
if (response.data.gameId) {
|
||||
console.log("GAMEID:" + response.data.gameId)
|
||||
gameId.value = response.data.gameId;
|
||||
}
|
||||
});
|
||||
})
|
||||
}
|
||||
|
||||
function clearUserInfo() {
|
||||
|
||||
@@ -37,10 +37,12 @@ export function useWebSocket() {
|
||||
};
|
||||
|
||||
onMounted(() => {
|
||||
console.log("Registering event handler for " + event);
|
||||
onEvent(event, wrapped);
|
||||
});
|
||||
|
||||
onBeforeUnmount(() => {
|
||||
console.log("Unregistering event handler for " + event);
|
||||
onEvent(event, () => {});
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user