Skip to content

Commit

Permalink
fix: fixing alarm not working after long break
Browse files Browse the repository at this point in the history
  • Loading branch information
egagofur committed Oct 15, 2023
1 parent a2a1f6d commit ac0878b
Showing 1 changed file with 47 additions and 51 deletions.
98 changes: 47 additions & 51 deletions components/Pomotime.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,6 @@ export const Pomotime = () => {

useEffect(() => {
if (state.timer.minutes === 0 && state.timer.seconds === 0) {
// Timer mencapai 0, maka panggil pemutaran suara
alarmPlay();
}
if (!state.timer.pause) {
Expand Down Expand Up @@ -181,57 +180,54 @@ export const Pomotime = () => {
}
}, (1 / speed) * 1000);
return () => clearTimeout(timer);
} else if (
state.status === "focus" &&
state.counter < replay &&
state.phase < 4
) {
setState((prev) => ({
...prev,
status: "shortBreak",
timer: {
...prev.timer,
pause: true,
minutes: shortBreak,
seconds: 0,
},
}));
} else if (state.status === "shortBreak") {
setState((prev) => ({
...prev,
status: "focus",
timer: {
...prev.timer,
pause: true,
minutes: focus,
seconds: 0,
},
phase: state.phase + 1,
}));
} else if (state.status === "longBreak") {
setState((prev) => ({
...prev,
status: "focus",
timer: {
...prev.timer,
pause: true,
minutes: focus,
seconds: 0,
},
phase: 1,
}));
} else {
setState((prev) => ({
...prev,
status: "longBreak",
timer: {
...prev.timer,
pause: true,
minutes: longBreak,
seconds: 0,
},
counter: 0,
}));
if (
state.status === "focus" &&
state.counter < replay &&
state.phase < 4
) {
setState((prev) => ({
...prev,
status: "shortBreak",
}));
} else if (state.status === "shortBreak") {
setState((prev) => ({
...prev,
status: "focus",
timer: {
...prev.timer,
pause: true,
minutes: focus,
seconds: 0,
},
phase: state.phase + 1,
}));
} else if (state.status === "longBreak" && state.phase === 4) {
alarmPlay();
setState((prev) => ({
...prev,
status: "focus",
timer: {
...prev.timer,
pause: true,
minutes: focus,
seconds: 0,
},
phase: 1,
}));
} else {
setState((prev) => ({
...prev,
status: "longBreak",
timer: {
...prev.timer,
pause: true,
minutes: longBreak,
seconds: 0,
},
counter: 0,
}));
}
}
}
}, [state.timer]);
Expand Down

0 comments on commit ac0878b

Please sign in to comment.