aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--frontend/app/components/GolfPlayApp.client.tsx23
-rw-r--r--frontend/app/components/GolfWatchApp.client.tsx23
2 files changed, 20 insertions, 26 deletions
diff --git a/frontend/app/components/GolfPlayApp.client.tsx b/frontend/app/components/GolfPlayApp.client.tsx
index d527e07..82c0928 100644
--- a/frontend/app/components/GolfPlayApp.client.tsx
+++ b/frontend/app/components/GolfPlayApp.client.tsx
@@ -47,30 +47,27 @@ export default function GolfPlayApp({
(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]);
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]);