diff --git a/front/volume/src/App.svelte b/front/volume/src/App.svelte
index 46f829e..f2c7126 100644
--- a/front/volume/src/App.svelte
+++ b/front/volume/src/App.svelte
@@ -1,3 +1,19 @@
+
+
@@ -29,11 +28,6 @@
{/if}
- {#if link.text === "Spectate"}
-
-
-
- {/if}
{#if link.text === "Channels"}
diff --git a/front/volume/src/components/Pong/Pong.svelte b/front/volume/src/components/Pong/Pong.svelte
index 75470df..74c81a9 100644
--- a/front/volume/src/components/Pong/Pong.svelte
+++ b/front/volume/src/components/Pong/Pong.svelte
@@ -10,22 +10,22 @@
import type { MatchmakingDto } from "./dtos/MatchmakingDto";
import { getUser, store } from "../../Auth";
import ColorPicker from "./ColorPicker.svelte";
+ import { APPSTATE } from "../../App.svelte";
export function inviteToGame(event: CustomEvent) {
- createMatchWindow = true;
+ setAppState(APPSTATE.CREATE_GAME);
invitedUsername = event.detail;
}
export let fakeUser: boolean;
+ export let appState: string;
+ export let setAppState: (newState: APPSTATE | string) => void;
const SERVER_URL = `ws://${import.meta.env.VITE_HOST}:${
import.meta.env.VITE_BACK_PORT
}`;
- let createMatchWindow: boolean = false;
- let spectateWindow: boolean = false;
let gamePlaying: boolean = false;
- let matchmaking: boolean = false;
let connected: boolean = false;
let loggedIn: boolean = false;
let failedLogIn: boolean = false;
@@ -87,7 +87,11 @@
} else if (event == GAME_EVENTS.CREATE_GAME) {
if (data) gamePlaying = true;
} else if (event == GAME_EVENTS.MATCHMAKING) {
- matchmaking = data.matchmaking;
+ if (data.matchmaking && appState !== APPSTATE.MATCHMAKING) {
+ setAppState(APPSTATE.MATCHMAKING);
+ } else if (!data.matchmaking && appState === APPSTATE.MATCHMAKING) {
+ setAppState(APPSTATE.HOME);
+ }
} else if (event == GAME_EVENTS.SPECTATE) {
if (data) {
gamePlaying = true;
@@ -141,9 +145,7 @@
}
function resetMenus() {
- createMatchWindow = false;
- spectateWindow = false;
- matchmaking = false;
+ setAppState(APPSTATE.HOME);
game.youAreReady = false;
}
@@ -152,6 +154,16 @@
game.updateColors(elementsColor, backgroundColor);
}
}
+
+ $: {
+ if (socket && socket.readyState) {
+ if (appState === APPSTATE.MATCHMAKING) {
+ startMatchmaking();
+ } else if (appState !== APPSTATE.MATCHMAKING) {
+ stopMatchmaking();
+ }
+ }
+ }
@@ -161,30 +173,32 @@
{:else if loggedIn}
Choose a gamemode
-