aboutsummaryrefslogtreecommitdiffhomepage
path: root/frontend/app/components/GolfWatchApp.client.tsx
diff options
context:
space:
mode:
authornsfisis <nsfisis@gmail.com>2024-08-11 23:11:42 +0900
committernsfisis <nsfisis@gmail.com>2024-08-11 23:11:42 +0900
commit7453eaaaf18827209ea296319b8b4bc38bde0950 (patch)
treeb071ceebe9926693ef032cd3d37d12c6defdfe90 /frontend/app/components/GolfWatchApp.client.tsx
parente65ee1dd3403b1572bb64217912b4bc466f65957 (diff)
downloadphperkaigi-2025-albatross-7453eaaaf18827209ea296319b8b4bc38bde0950.tar.gz
phperkaigi-2025-albatross-7453eaaaf18827209ea296319b8b4bc38bde0950.tar.zst
phperkaigi-2025-albatross-7453eaaaf18827209ea296319b8b4bc38bde0950.zip
feat(frontend): allow users to re-connect
Diffstat (limited to 'frontend/app/components/GolfWatchApp.client.tsx')
-rw-r--r--frontend/app/components/GolfWatchApp.client.tsx26
1 files changed, 25 insertions, 1 deletions
diff --git a/frontend/app/components/GolfWatchApp.client.tsx b/frontend/app/components/GolfWatchApp.client.tsx
index cef6f9a..448a966 100644
--- a/frontend/app/components/GolfWatchApp.client.tsx
+++ b/frontend/app/components/GolfWatchApp.client.tsx
@@ -194,11 +194,35 @@ export default function GolfWatchApp({
});
}
} else {
- setGameState("waiting");
+ if (game.started_at) {
+ const nowSec = Math.floor(Date.now() / 1000);
+ if (game.started_at <= nowSec) {
+ // The game has already started.
+ if (gameState !== "gaming" && gameState !== "finished") {
+ setStartedAt(game.started_at);
+ setLeftTimeSeconds(0);
+ setGameState("gaming");
+ }
+ } else {
+ // The game is starting.
+ if (
+ gameState !== "starting" &&
+ gameState !== "gaming" &&
+ gameState !== "finished"
+ ) {
+ setStartedAt(game.started_at);
+ setLeftTimeSeconds(game.started_at - nowSec);
+ setGameState("starting");
+ }
+ }
+ } else {
+ setGameState("waiting");
+ }
}
}
}, [
game.verification_steps,
+ game.started_at,
lastJsonMessage,
readyState,
gameState,