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/GolfPlayApp.client.tsx | |
| parent | 545d86085f927bded852dd5a8ee8341f60f24d84 (diff) | |
| download | iosdc-japan-2024-albatross-b37d6f213c2f3b19631e5067f39a7106859faaed.tar.gz iosdc-japan-2024-albatross-b37d6f213c2f3b19631e5067f39a7106859faaed.tar.zst iosdc-japan-2024-albatross-b37d6f213c2f3b19631e5067f39a7106859faaed.zip | |
feat: show left time in play page
Diffstat (limited to 'frontend/app/components/GolfPlayApp.client.tsx')
| -rw-r--r-- | frontend/app/components/GolfPlayApp.client.tsx | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/frontend/app/components/GolfPlayApp.client.tsx b/frontend/app/components/GolfPlayApp.client.tsx index dbc8c1b..d527e07 100644 --- a/frontend/app/components/GolfPlayApp.client.tsx +++ b/frontend/app/components/GolfPlayApp.client.tsx @@ -43,16 +43,17 @@ export default function GolfPlayApp({ 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; }); @@ -196,7 +197,7 @@ export default function GolfPlayApp({ // The game has already started. if (gameState !== "gaming" && gameState !== "finished") { setStartedAt(game.started_at); - setLeftTimeSeconds(0); + setLeftTimeSeconds(game.started_at - nowSec); setGameState("gaming"); } } else { @@ -234,6 +235,8 @@ export default function GolfPlayApp({ return ( <GolfPlayAppGaming gameDisplayName={game.display_name} + gameDurationSeconds={game.duration_seconds} + leftTimeSeconds={leftTimeSeconds!} playerInfo={playerInfo} problemTitle={game.problem.title} problemDescription={game.problem.description} |
