mirror of
https://github.com/R0m1k3/noteflow.git
synced 2026-10-23 15:18:16 +02:00
Merge pull request #151 from R0m1k3/claude/fix-pomodoro-tab-switch-01WFQEsfPro5ynAgg4VAU3EV
fix: permettre au timer Pomodoro de continuer en arrière-plan
This commit is contained in:
1 file changed
+27
@@ -73,6 +73,33 @@ export function PomodoroTimer({ onStateChange }: PomodoroTimerProps = {}) {
|
|||||||
window.dispatchEvent(new CustomEvent('pomodoroStateChange'));
|
window.dispatchEvent(new CustomEvent('pomodoroStateChange'));
|
||||||
}, [endTime]);
|
}, [endTime]);
|
||||||
|
|
||||||
|
// Restore timer state on mount if it was running
|
||||||
|
useEffect(() => {
|
||||||
|
// Clean up invalid states on mount
|
||||||
|
if (isRunning && endTime === null) {
|
||||||
|
// If running but no endTime, stop the timer
|
||||||
|
setIsRunning(false);
|
||||||
|
setTimeLeft(TIMER_DURATIONS[mode]);
|
||||||
|
} else if (endTime !== null && isRunning) {
|
||||||
|
// Recalculate remaining time based on endTime
|
||||||
|
const now = Date.now();
|
||||||
|
const remaining = Math.max(0, Math.ceil((endTime - now) / 1000));
|
||||||
|
|
||||||
|
if (remaining > 0) {
|
||||||
|
setTimeLeft(remaining);
|
||||||
|
} else {
|
||||||
|
// Timer expired while page was closed/reloaded
|
||||||
|
setIsRunning(false);
|
||||||
|
setEndTime(null);
|
||||||
|
setTimeLeft(0);
|
||||||
|
}
|
||||||
|
} else if (endTime !== null && !isRunning) {
|
||||||
|
// If paused with an endTime, clean up the endTime
|
||||||
|
setEndTime(null);
|
||||||
|
}
|
||||||
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||||
|
}, []); // Run only on mount
|
||||||
|
|
||||||
// Listen for localStorage changes from other instances
|
// Listen for localStorage changes from other instances
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const handleStorageChange = () => {
|
const handleStorageChange = () => {
|
||||||
|
|||||||
Reference in new issue
Block a user