diff --git a/SerpentRace_Frontend/src/pages/Game/Lobby.jsx b/SerpentRace_Frontend/src/pages/Game/Lobby.jsx
index bfee0932..68f94c39 100644
--- a/SerpentRace_Frontend/src/pages/Game/Lobby.jsx
+++ b/SerpentRace_Frontend/src/pages/Game/Lobby.jsx
@@ -1,5 +1,7 @@
import React, { useEffect, useRef, useState } from "react"
import { useLocation } from "react-router-dom"
+import { useNavigate } from "react-router-dom"
+import { notifyError, notifyWarning, notifySuccess } from "../../components/Toastify/toastifyServices"
import HandleNavigate from "../../utils/HandleNavigate/HandleNavigate"
import Navbar from "../../components/Navbar/Navbar.jsx"
import Background from "../../assets/backgrounds/Background.jsx"
@@ -12,10 +14,11 @@ const Lobby = () => {
const [isStarting, setIsStarting] = useState(false)
const sectionRef = useRef(null)
const { goHome, goGame } = HandleNavigate()
+ const navigate = useNavigate()
const location = useLocation()
const [user, setUser] = useRequireAuth()
-
+
// Get game code from location state or WebSocket
const gameCodeFromState = location.state?.gameCode
const gameToken = localStorage.getItem('gameToken')
@@ -41,8 +44,8 @@ const Lobby = () => {
}
}, [gameToken, connect])
- const gameCode = gameCodeFromState || gameState?.gameCode || 'Loading...'
-
+ const gameCode = gameCodeFromState || gameState?.gameCode || "Loading..."
+
// Players list - gamemaster is separate, don't filter
// Backend should handle this correctly
const currentPlayers = players || []
@@ -50,12 +53,12 @@ const Lobby = () => {
// Debug logging
useEffect(() => {
if (import.meta.env.DEV) {
- console.log('🎮 Lobby state update:')
- console.log(' - isGamemaster:', isGamemaster)
- console.log(' - gameState:', gameState)
- console.log(' - players:', players)
- console.log(' - currentPlayers:', currentPlayers)
- console.log(' - pendingPlayers:', pendingPlayers)
+ console.log("🎮 Lobby state update:")
+ console.log(" - isGamemaster:", isGamemaster)
+ console.log(" - gameState:", gameState)
+ console.log(" - players:", players)
+ console.log(" - currentPlayers:", currentPlayers)
+ console.log(" - pendingPlayers:", pendingPlayers)
}
}, [isGamemaster, gameState, players, currentPlayers, pendingPlayers])
@@ -73,7 +76,7 @@ const Lobby = () => {
// Auto-navigate when game starts
useEffect(() => {
if (gameStarted) {
- console.log('🎮 Game started, navigating to /game')
+ console.log("🎮 Game started, navigating to /game")
goGame()
}
}, [gameStarted, goGame])
@@ -83,7 +86,7 @@ const Lobby = () => {
if (approvalStatus === 'denied') {
alert('A gamemaster elutasította a csatlakozási kérelmedet.')
localStorage.removeItem('gameToken')
- goHome()
+ navigate("/home")
} else if (approvalStatus === 'approved') {
console.log('✅ Join approved, you can now see the lobby')
}
@@ -91,7 +94,8 @@ const Lobby = () => {
const handleExit = () => {
if (window.confirm("Biztosan ki szeretnél lépni a lobbyból?")) {
- localStorage.removeItem('gameToken')
+ localStorage.removeItem("gameToken")
+ notifyWarning("Kiléptél a lobbyból.")
goHome()
}
}
@@ -99,44 +103,44 @@ const Lobby = () => {
const handleStartGame = async () => {
// Prevent double-click
if (isStarting) {
- console.log('⚠️ Game start already in progress, ignoring duplicate request')
+ console.log("⚠️ Game start already in progress, ignoring duplicate request")
return
}
-
+
try {
setIsStarting(true)
-
+
// Get gameId from gameState
const gameId = gameState?.gameId
if (!gameId) {
- alert('Hiba: Játék azonosító nem található')
+ notifyError("Hiba: Játék azonosító nem található")
return
}
- console.log('Starting game with ID:', gameId)
+ console.log("Starting game with ID:", gameId)
const response = await startGame(gameId)
- console.log('Game start response:', response)
-
+ console.log("Game start response:", response)
+
// Store boardData and updated game state for GameScreen
if (response.boardData) {
- localStorage.setItem('boardData', JSON.stringify(response.boardData))
- console.log('✅ boardData stored in localStorage')
+ localStorage.setItem("boardData", JSON.stringify(response.boardData))
+ console.log("✅ boardData stored in localStorage")
}
-
+
// Navigate immediately after successful start (don't wait for WebSocket)
console.log('🎮 Navigating to /game...')
- goGame()
+ navigate('/game')
} catch (error) {
- console.error('Failed to start game:', error)
-
+ console.error("Failed to start game:", error)
+
// Check if game already started
if (error.response?.status === 409) {
- console.log('Game already started, navigating to /game...')
+ console.log("Game already started, navigating to /game...")
// Navigate anyway - game is already running
- goGame()
+ navigate('/game')
} else {
- alert(`Nem sikerült elindítani a játékot: ${error.response?.data?.error || error.message}`)
+ notifyError(`Nem sikerült elindítani a játékot: ${error.response?.data?.error || error.message}`)
}
} finally {
setIsStarting(false)
@@ -145,7 +149,7 @@ const Lobby = () => {
const copyGameCode = () => {
navigator.clipboard.writeText(gameCode)
- alert('Játék kód vágólapra másolva: ' + gameCode)
+ notifySuccess("Játék kód vágólapra másolva: " + gameCode)
}
const handleApprovePlayer = (playerName) => {
@@ -155,8 +159,9 @@ const Lobby = () => {
}
const handleRejectPlayer = (playerName) => {
- const reason = prompt(`Miért utasítod el ${playerName}-t?`, 'Nincs hely a játékban')
- if (reason !== null) { // User didn't cancel
+ const reason = prompt(`Miért utasítod el ${playerName}-t?`, "Nincs hely a játékban")
+ if (reason !== null) {
+ // User didn't cancel
if (rejectPlayer(playerName, reason)) {
console.log(`❌ Player ${playerName} rejected`)
}
@@ -183,7 +188,7 @@ const Lobby = () => {
{/* Waiting for Approval Screen (Non-gamemaster, PRIVATE games) */}
- {!isGamemaster && approvalStatus === 'pending' && (
+ {!isGamemaster && approvalStatus === "pending" && (
@@ -192,9 +197,7 @@ const Lobby = () => {
⏳
-
- Várakozás jóváhagyásra
-
+
Várakozás jóváhagyásra
A gamemaster még nem hagyta jóvá a csatlakozásodat.
@@ -204,9 +207,7 @@ const Lobby = () => {
Játék kód:
-
- {gameCode}
-
+
{gameCode}