From 3b9db03138702a0646f3726a891f6c92ae2abf2a Mon Sep 17 00:00:00 2001 From: MacielG1 Date: Fri, 26 Jul 2024 17:22:23 -0300 Subject: [PATCH] skip when rest time is 0 --- src/components/MainMenu.tsx | 64 +++++++++++++++++++++++++++---------- 1 file changed, 47 insertions(+), 17 deletions(-) diff --git a/src/components/MainMenu.tsx b/src/components/MainMenu.tsx index 3dba5cc..682245f 100644 --- a/src/components/MainMenu.tsx +++ b/src/components/MainMenu.tsx @@ -33,7 +33,7 @@ export default function MainMenu() { const preferredLanguage = useStore((state) => state.preferredLanguage); useEffect(() => { - let isMounted = true; // used in the cleanup function + let isMounted = true; // used in the cleanup function if (timer && isMounted) { if (workoutFullTime === "00:00") { @@ -61,15 +61,34 @@ export default function MainMenu() { setMainTimerBorder(workColor); } } else if (whichInterval === "rest") { - setProgressBarMax(restTime); - setCurrentProgressColor(restColor); - if (enableBackgroundColors) { - setCurrentBackgroundColor(restColor); - setRemoveUIBorders(true); + if (restTime === "0") { + // Skip rest interval if restTime is 0 + if (currentRound === totalRounds) { + timer?.stop(); + resetTimer(); + return; + } else { + currentRoundIncrease(); + if (prepareonEveryRound) { + setWhichInterval("prepare"); + } else { + setWhichInterval("work"); + } + setTime(0); + return; // ensure we don't execute further code in this cycle + } } else { - setMainTimerBorder(restColor); + setProgressBarMax(restTime); + setCurrentProgressColor(restColor); + if (enableBackgroundColors) { + setCurrentBackgroundColor(restColor); + setRemoveUIBorders(true); + } else { + setMainTimerBorder(restColor); + } } } + if (enableSounds) { if (whichInterval === "work" && time == 0) { playSound(sound1); @@ -87,13 +106,24 @@ export default function MainMenu() { setWhichInterval("work"); setTime(0); } else if (whichInterval === "work" && time > +workTime) { - setWhichInterval("rest"); - setTime(0); - - if (currentRound === totalRounds && skipLastRest) { - timer?.stop(); - resetTimer(); - return; + if (restTime !== "0") { + setWhichInterval("rest"); + setTime(0); // reset the time for the rest interval + } else { + // Skip directly to next interval if restTime is 0 + if (currentRound === totalRounds && skipLastRest) { + timer?.stop(); + resetTimer(); + return; + } else { + currentRoundIncrease(); + if (prepareonEveryRound) { + setWhichInterval("prepare"); + } else { + setWhichInterval("work"); + } + setTime(0); + } } } else if (whichInterval === "rest" && time > +restTime) { if (currentRound === totalRounds) { @@ -122,10 +152,10 @@ export default function MainMenu() { return ( <> -
-
+
+
{/* Rounds */} - +