aboutsummaryrefslogtreecommitdiffhomepage
path: root/frontend/app/components/Gaming/Score.tsx
diff options
context:
space:
mode:
Diffstat (limited to 'frontend/app/components/Gaming/Score.tsx')
-rw-r--r--frontend/app/components/Gaming/Score.tsx30
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}