Skip to content

Commit

Permalink
[fix] counter fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
yixuan-zhou-uzh committed Apr 25, 2024
1 parent 097325e commit 5b9ca84
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/components/views/Gameroom.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -97,16 +97,22 @@ const Gameroom = () => {
console.log("GameInfo", gameInfo);

function calculateRemainingTime(roundDue) {
roundDue = roundDue.split('[')[0];
const endTime = new Date(roundDue).getTime();
console.log("ENDTIME IS " + endTime);
const currentTime = Date.now();
console.log("CURRENT TIME IS " + currentTime);
const remainingSeconds = Math.max(0, Math.floor((endTime - currentTime) / 1000));

console.log("REMAINING SECONDS: " + remainingSeconds);

return remainingSeconds;
}

useEffect(() => {
const interval = setInterval(() => {
setRemainingTime(calculateRemainingTime(endTime));
console.log(remainingTime)
console.log("!!!!")
}, 1000);

return () => clearInterval(interval);
Expand Down Expand Up @@ -1066,7 +1072,7 @@ const Gameroom = () => {
onClick={() => getReady()}
onKeyDown={() => getReady()}
>
Confirm, {gameInfo.roomOwner.id},{user.id}
Confirm
</div>
<div
className="gameroom cancelbutton"
Expand Down

0 comments on commit 5b9ca84

Please sign in to comment.