diff options
| author | nsfisis <nsfisis@gmail.com> | 2026-02-14 00:21:30 +0900 |
|---|---|---|
| committer | nsfisis <nsfisis@gmail.com> | 2026-02-14 00:21:30 +0900 |
| commit | 6588e61674059612dc95c3216f54720b1c42f6ee (patch) | |
| tree | 4ff7cdf1b0fa97289ff5deaf795a7ed15e022a75 /frontend/app/components/Gaming/Score.tsx | |
| parent | 7258ca81812a24edd382438ce6e9ebc538549427 (diff) | |
| download | phperkaigi-2026-albatross-6588e61674059612dc95c3216f54720b1c42f6ee.tar.gz phperkaigi-2026-albatross-6588e61674059612dc95c3216f54720b1c42f6ee.tar.zst phperkaigi-2026-albatross-6588e61674059612dc95c3216f54720b1c42f6ee.zip | |
feat(frontend): update dependencies
Diffstat (limited to 'frontend/app/components/Gaming/Score.tsx')
| -rw-r--r-- | frontend/app/components/Gaming/Score.tsx | 30 |
1 files changed, 14 insertions, 16 deletions
diff --git a/frontend/app/components/Gaming/Score.tsx b/frontend/app/components/Gaming/Score.tsx index b4a415c..ee23a6c 100644 --- a/frontend/app/components/Gaming/Score.tsx +++ b/frontend/app/components/Gaming/Score.tsx @@ -6,30 +6,28 @@ type Props = { }; export default function Score({ status, score }: Props) { - const [displayScore, setDisplayScore] = useState(score); + const [randomScore, setRandomScore] = useState<number | null>(null); useEffect(() => { - let intervalId = null; - - if (status === "running") { - intervalId = setInterval(() => { - const maxValue = Math.pow(10, String(score ?? 100).length) - 1; - const minValue = Math.pow(10, String(score ?? 100).length - 1); - const randomValue = - Math.floor(Math.random() * (maxValue - minValue + 1)) + minValue; - setDisplayScore(randomValue); - }, 50); - } else { - setDisplayScore(score); + if (status !== "running") { + return; } + const intervalId = setInterval(() => { + const maxValue = Math.pow(10, String(score ?? 100).length) - 1; + const minValue = Math.pow(10, String(score ?? 100).length - 1); + const randomValue = + Math.floor(Math.random() * (maxValue - minValue + 1)) + minValue; + setRandomScore(randomValue); + }, 50); + return () => { - if (intervalId) { - clearInterval(intervalId); - } + clearInterval(intervalId); }; }, [status, score]); + const displayScore = status === "running" ? randomScore : score; + return ( <span className={status === "running" ? "animate-pulse" : ""}> {displayScore} |
