Skip to content

Commit

Permalink
fix: timer (#6)
Browse files Browse the repository at this point in the history
  • Loading branch information
rossy0213 authored Dec 31, 2023
1 parent 4beebe2 commit 8ae2634
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ function App() {
const [bellType, setBellType] = useState(BellType.Normal);
const [isCriminal, setIsCriminal] = useState(false);
const [ringingType, setRingingType] = useState("bell ring");
const [startTime, setStartTime] = useState(0);

const bellRef = useRef<bellRefT>(null!);

Expand Down Expand Up @@ -166,7 +167,10 @@ function App() {

if (lustCnt + cnt >= lustLimit) {
setIsPerfectHuman(true);
setTime(new Date().getTime() - startTime);
setTimerActive(false);
bellRef.current.kotoSound.play();
return;
}

setLustCnt(lustCnt => lustCnt + cnt);
Expand All @@ -189,7 +193,8 @@ function App() {
initKotoSound();
initScreamSound();
initDoorSound();
initBonusSound;
initBonusSound();
setStartTime(new Date().getTime());
bellRef.current.kongSound.play();
};

Expand Down Expand Up @@ -224,17 +229,15 @@ function App() {

if (timerActive) {
const tick = () => {
setTime(prevTime => prevTime + 10);
timeout = setTimeout(tick, 10);
setTime(prevTime => prevTime + 37);
timeout = setTimeout(tick, 37);
};

if (lustCnt !== lustLimit) {
tick();
}
tick();
}

return () => clearTimeout(timeout);
}, [timerActive, lustCnt]);
}, [timerActive]);

return (
<div className="App">
Expand Down

1 comment on commit 8ae2634

@vercel
Copy link

@vercel vercel bot commented on 8ae2634 Dec 31, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

newyearsbell – ./

newyearsbell-yoidea.vercel.app
newyearsbell-git-master-yoidea.vercel.app
newyearsbell.vercel.app

Please sign in to comment.