Skip to content

Commit

Permalink
skip when rest time is 0
Browse files Browse the repository at this point in the history
  • Loading branch information
MacielG1 committed Jul 26, 2024
1 parent 784e382 commit 3b9db03
Showing 1 changed file with 47 additions and 17 deletions.
64 changes: 47 additions & 17 deletions src/components/MainMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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") {
Expand Down Expand Up @@ -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);
Expand All @@ -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) {
Expand Down Expand Up @@ -122,10 +152,10 @@ export default function MainMenu() {

return (
<>
<div className="mt-6 flex flex-col justify-center gap-2 min-[350px]:mx-auto 2xl:mt-8 2xl:gap-3 ">
<div className="flex ">
<div className="mt-6 flex flex-col justify-center gap-2 min-[350px]:mx-auto 2xl:mt-8 2xl:gap-3">
<div className="flex">
{/* Rounds */}
<InputNumber label={lang.rounds[preferredLanguage]} className="w-[8rem] xs:w-[9.65rem] " inputStoreType="Rounds" maxLength={8} />
<InputNumber label={lang.rounds[preferredLanguage]} className="w-[8rem] xs:w-[9.65rem]" inputStoreType="Rounds" maxLength={8} />
<ClearInput />
</div>

Expand Down

0 comments on commit 3b9db03

Please sign in to comment.