From 53c616559f8364d41cb117736eb3b0137655fed4 Mon Sep 17 00:00:00 2001 From: Dario Date: Tue, 9 Apr 2024 04:01:01 +0200 Subject: [PATCH] chore: fixed loading --- webapp/src/pages/Game.jsx | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/webapp/src/pages/Game.jsx b/webapp/src/pages/Game.jsx index ed934025..d5f875b2 100644 --- a/webapp/src/pages/Game.jsx +++ b/webapp/src/pages/Game.jsx @@ -65,7 +65,7 @@ export default function Game() { const startNewRound = async (gameId) => { try{ const result = await startRound(gameId); - setTimeStartRound(new Date(result.data.round_start_time).getUTCMilliseconds()); + setTimeStartRound(new Date(result.data.round_start_time).getTime()); setRoundNumber(result.data.actual_round ) setRoundDuration(result.data.round_duration); await assignQuestion(gameId); @@ -93,17 +93,20 @@ export default function Game() { const newGameResponse = await newGame(); if (newGameResponse) { setGameId(newGameResponse.id); - setTimeStartRound(new Date(newGameResponse.round_start_time).getUTCMilliseconds()); + setTimeStartRound(new Date(newGameResponse.round_start_time).getTime()); setRoundDuration(newGameResponse.round_duration) setMaxRoundNumber(newGameResponse.rounds); - getCurrentQuestion(newGameResponse.id).then((result) => { - if (result.status === 200) { + try{ + const result = await getCurrentQuestion(newGameResponse.id); + if (result.status === HttpStatusCode.Ok) { setQuestion(result.data); setNextDisabled(false); + setLoading(false); } - }).catch(() => { + }catch(error){ startNewRound(newGameResponse.id); - }) + } + } else { navigate("/dashboard"); @@ -158,9 +161,7 @@ export default function Game() { useEffect(() => { let timeout; - - //console.log(timeElapsed) - if ((new Date().getUTCMilliseconds() - timeStartRound)/1000 >= roundDuration && timeStartRound !== -1) { + if (timeElapsed >= roundDuration && timeStartRound !== -1) { timeout = setTimeout(() => nextRound(), 1000); } else {