aboutsummaryrefslogtreecommitdiffhomepage
path: root/frontend/app/components/GolfWatchApp.client.tsx
diff options
context:
space:
mode:
authornsfisis <nsfisis@gmail.com>2024-08-12 11:07:16 +0900
committernsfisis <nsfisis@gmail.com>2024-08-12 11:07:16 +0900
commit5a4de49ea8a3f06568fed7863b5085750b94a149 (patch)
tree5e9e638c5e4fb0c3da876bb4a79d50277c28003e /frontend/app/components/GolfWatchApp.client.tsx
parent1cd22671a6bacaa7bde2cd17f78a5ba8899e8d40 (diff)
downloadiosdc-japan-2025-albatross-5a4de49ea8a3f06568fed7863b5085750b94a149.tar.gz
iosdc-japan-2025-albatross-5a4de49ea8a3f06568fed7863b5085750b94a149.tar.zst
iosdc-japan-2025-albatross-5a4de49ea8a3f06568fed7863b5085750b94a149.zip
fix(frontend): fix an issue where game does not finish
Diffstat (limited to 'frontend/app/components/GolfWatchApp.client.tsx')
-rw-r--r--frontend/app/components/GolfWatchApp.client.tsx23
1 files changed, 10 insertions, 13 deletions
diff --git a/frontend/app/components/GolfWatchApp.client.tsx b/frontend/app/components/GolfWatchApp.client.tsx
index 15b78dc..7eb20cf 100644
--- a/frontend/app/components/GolfWatchApp.client.tsx
+++ b/frontend/app/components/GolfWatchApp.client.tsx
@@ -43,30 +43,27 @@ export default function GolfWatchApp({
(gameState === "starting" || gameState === "gaming") &&
startedAt !== null
) {
- const timer1 = setInterval(() => {
+ const timer = setInterval(() => {
setLeftTimeSeconds((prev) => {
if (prev === null) {
return null;
}
if (prev <= 1) {
- setGameState("gaming");
+ const nowSec = Math.floor(Date.now() / 1000);
+ const finishedAt = startedAt + game.duration_seconds;
+ if (nowSec >= finishedAt) {
+ clearInterval(timer);
+ setGameState("finished");
+ } else {
+ setGameState("gaming");
+ }
}
return prev - 1;
});
}, 1000);
- const timer2 = setInterval(() => {
- const nowSec = Math.floor(Date.now() / 1000);
- const finishedAt = startedAt + game.duration_seconds;
- if (nowSec >= finishedAt) {
- clearInterval(timer2);
- setGameState("finished");
- }
- }, 1000);
-
return () => {
- clearInterval(timer1);
- clearInterval(timer2);
+ clearInterval(timer);
};
}
}, [gameState, startedAt, game.duration_seconds]);