Skip to content

Commit

Permalink
refactor timer component
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelthorpe committed Oct 27, 2023
1 parent a0b1491 commit 5359317
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion components/timeout-modal/src/TimeoutModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export const TimeoutModal: FC<TimeoutModalProps> = ({
classBlock,
classModifiers,
className,
isOpen = true,
isOpen,
timerDurationInSeconds,
onContinue,
onSignout,
Expand Down
10 changes: 5 additions & 5 deletions components/timeout-modal/src/Timer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export const Timer: FC<TimerProps> = ({
}) => {
const [runTimer, setRunTimer] = useState(true)
const [timer, setTimer] = useState(timerFrom);
let formattedTimer = timer < 60 ? Math.ceil(timer / 20) * 20 : Math.round(timer / 60);
let formattedTimer = timer < 60 ? Math.ceil(timer / 20) * 20 : Math.ceil(timer / 60);

useEffect(() => {
let interval;
Expand All @@ -27,7 +27,7 @@ export const Timer: FC<TimerProps> = ({
return () => clearInterval(interval);
}, [runTimer])

useEffect(() => {
if(runTimer) {
if(timer > 60) {
if(timer % 60 == 0) {
formattedTimer = Math.round(timer / 60);
Expand All @@ -36,14 +36,14 @@ export const Timer: FC<TimerProps> = ({
if([60,40,20,0].includes(timer)) {
formattedTimer = timer;
if(timer == 0) {
onTimeout;
setRunTimer(false);
onTimeout;
}
}
}
}, [timer])
}

useEffect(() => { return () => setRunTimer(false) }, []);
console.log(timer);

return (
<span {...attrs}>{formattedTimer} {timer <= 60 ? "seconds" : formattedTimer == 1 ? "minute" : "minutes"}</span>
Expand Down

1 comment on commit 5359317

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

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

Please sign in to comment.