Skip to content

Commit f494d8e

Browse files
committed
Fixed all deployment issue
1 parent b780969 commit f494d8e

File tree

1 file changed

+28
-11
lines changed

1 file changed

+28
-11
lines changed

src/app/click-the-circle/page.tsx

+28-11
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,30 @@ const Circle = () => {
77
const [circleClicked, setCircleClicked] = useState(0);
88
const [totalClicked, setTotalClicked] = useState(0);
99
const [timeLeft, setTimeLeft] = useState(10);
10-
const screenWidth = window.innerWidth;
11-
const screenHeight = window.innerHeight;
10+
const [screenSize, setScreenSize] = useState({ width: 0, height: 0 });
11+
12+
useEffect(() => {
13+
const updateScreenSize = () => {
14+
setScreenSize({
15+
width: window.innerWidth,
16+
height: window.innerHeight,
17+
});
18+
};
19+
20+
updateScreenSize();
21+
window.addEventListener("resize", updateScreenSize);
22+
23+
return () => {
24+
window.removeEventListener("resize", updateScreenSize);
25+
};
26+
}, []);
27+
1228
const position = useRef({
13-
top: Math.floor(Math.random() * (screenHeight - radius * 2)),
14-
left: Math.floor(Math.random() * (screenWidth - radius * 2)),
29+
top: Math.floor(Math.random() * (screenSize.height - radius * 2)),
30+
left: Math.floor(Math.random() * (screenSize.width - radius * 2)),
1531
transform: "translate(-50%, -50%)",
1632
});
33+
1734
const clicked = () => {
1835
setCircleClicked((prevCount) => {
1936
console.log("outside: ", circleClicked);
@@ -26,11 +43,12 @@ const Circle = () => {
2643
console.log("Total click:", totalClicked);
2744
};
2845

29-
const accuracy = (circleClicked / totalClicked) * 100;
46+
const accuracy = totalClicked > 0 ? (circleClicked / totalClicked) * 100 : 0;
3047

3148
const circleClickedFunc = () => {
3249
setRadius(0);
3350
};
51+
3452
useEffect(() => {
3553
const interval = setInterval(() => {
3654
if (timeLeft > 0) {
@@ -63,16 +81,16 @@ const Circle = () => {
6381
}, []);
6482

6583
useEffect(() => {
66-
if (radius == 0) {
67-
const newTop = Math.floor(Math.random() * (screenHeight - radius * 2));
68-
const newLeft = Math.floor(Math.random() * (screenWidth - radius * 2));
84+
if (radius === 0) {
85+
const newTop = Math.floor(Math.random() * (screenSize.height - radius * 2));
86+
const newLeft = Math.floor(Math.random() * (screenSize.width - radius * 2));
6987
position.current = {
7088
...position.current,
7189
top: newTop,
7290
left: newLeft,
7391
};
7492
}
75-
}, [increasing, radius, screenHeight, screenWidth]);
93+
}, [increasing, radius, screenSize.height, screenSize.width]);
7694

7795
return (
7896
<>
@@ -84,7 +102,6 @@ const Circle = () => {
84102
style={position.current}
85103
>
86104
<div
87-
// onClick={clicked()}
88105
onClick={circleClickedFunc}
89106
className="rounded-full bg-blue-500"
90107
style={{ width: radius, height: radius }}
@@ -94,7 +111,7 @@ const Circle = () => {
94111
) : (
95112
<div className="h-screen w-full flex flex-col justify-center items-center">
96113
<h1>Time&apos;s up</h1>
97-
<h1>Your accuray: {accuracy}</h1>
114+
<h1>Your accuracy: {accuracy.toFixed(2)}%</h1>
98115
</div>
99116
)}
100117
</>

0 commit comments

Comments
 (0)