diff options
| author | nsfisis <nsfisis@gmail.com> | 2024-08-12 05:54:37 +0900 |
|---|---|---|
| committer | nsfisis <nsfisis@gmail.com> | 2024-08-12 05:54:37 +0900 |
| commit | b37d6f213c2f3b19631e5067f39a7106859faaed (patch) | |
| tree | 3c45267ee25aa78be1ad4c31e0c09894e656b506 /frontend/app/components/GolfWatchApp.client.tsx | |
| parent | 545d86085f927bded852dd5a8ee8341f60f24d84 (diff) | |
| download | phperkaigi-2025-albatross-b37d6f213c2f3b19631e5067f39a7106859faaed.tar.gz phperkaigi-2025-albatross-b37d6f213c2f3b19631e5067f39a7106859faaed.tar.zst phperkaigi-2025-albatross-b37d6f213c2f3b19631e5067f39a7106859faaed.zip | |
feat: show left time in play page
Diffstat (limited to 'frontend/app/components/GolfWatchApp.client.tsx')
| -rw-r--r-- | frontend/app/components/GolfWatchApp.client.tsx | 14 |
1 files changed, 8 insertions, 6 deletions
diff --git a/frontend/app/components/GolfWatchApp.client.tsx b/frontend/app/components/GolfWatchApp.client.tsx index 9d3f752..b2f3b69 100644 --- a/frontend/app/components/GolfWatchApp.client.tsx +++ b/frontend/app/components/GolfWatchApp.client.tsx @@ -39,16 +39,17 @@ export default function GolfWatchApp({ const [leftTimeSeconds, setLeftTimeSeconds] = useState<number | null>(null); useEffect(() => { - if (gameState === "starting" && startedAt !== null) { + if ( + (gameState === "starting" || gameState === "gaming") && + startedAt !== null + ) { const timer1 = setInterval(() => { setLeftTimeSeconds((prev) => { if (prev === null) { return null; } if (prev <= 1) { - clearInterval(timer1); setGameState("gaming"); - return 0; } return prev - 1; }); @@ -207,7 +208,7 @@ export default function GolfWatchApp({ // The game has already started. if (gameState !== "gaming" && gameState !== "finished") { setStartedAt(game.started_at); - setLeftTimeSeconds(0); + setLeftTimeSeconds(game.started_at - nowSec); setGameState("gaming"); } } else { @@ -245,10 +246,11 @@ export default function GolfWatchApp({ } else if (gameState === "gaming") { return ( <GolfWatchAppGaming - problem={game.problem!.description} + gameDurationSeconds={game.duration_seconds} + leftTimeSeconds={leftTimeSeconds!} playerInfoA={playerInfoA} playerInfoB={playerInfoB} - leftTimeSeconds={leftTimeSeconds!} + problem={game.problem!.description} /> ); } else if (gameState === "finished") { |
