Skip to content

Commit

Permalink
Fix counting stopped at 00:00:01
Browse files Browse the repository at this point in the history
  • Loading branch information
roman-drozd-it committed Apr 24, 2024
1 parent 56f7cff commit 788b98b
Showing 1 changed file with 5 additions and 18 deletions.
23 changes: 5 additions & 18 deletions src/views/room/Room.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,34 +47,21 @@ const Room = (): JSX.Element => {

useEffect(() => {

// let _countdownTimerRef: NodeJS.Timeout | undefined = undefined;
let _countdownTimerRef: NodeJS.Timeout | null = null;

if (isStarted && !_countdownTimerRef) {
if (isStarted) {

_countdownTimerRef = setInterval(() => {
const _countdownTimerRef = setInterval(() => {
let leftUnix = moment(`1000-01-01 ${left}`).unix();
const endUnix = moment('1000-01-01 00:00:00').unix();

leftUnix--;

const leftString = moment.unix(leftUnix).format('HH:mm:ss');

dispatch(countdownTimerSlices.setCountdownTimer({ left: leftString }));

if (leftUnix === endUnix) {
dispatch(countdownTimerActions.stopCountdownTimer());
}

}, 1000);
} else if (_countdownTimerRef) clearInterval(_countdownTimerRef);

return (): void => {
if (_countdownTimerRef) {
clearInterval(_countdownTimerRef);
_countdownTimerRef = null;
}
};

return () => { clearInterval(_countdownTimerRef); };
}

}, [ isStarted, left, dispatch ]);

Expand Down

0 comments on commit 788b98b

Please sign in to comment.