Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,8 @@ Now behavior:
- Now is session-local UI state and is not persisted to SQLite.
- Reopening the app should start with no Now task selected.
- When Now is active, the Now TODO title is emphasized and other incomplete TODO titles are dimmed.
- Setting Now resets the Pomodoro timer to `25:00` and starts focus.
- Setting Now resets the Pomodoro timer to the configured focus duration and starts focus when the timer is idle or paused.
- Setting Now while the Pomodoro timer is already running only updates Now and does not reset the remaining time.
- Unsetting Now does not stop the Pomodoro timer.
- Completing the Now task clears Now but does not stop the Pomodoro timer.

Expand Down
13 changes: 11 additions & 2 deletions src/lib/components/PomodoroSection.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
pomodoroStatus,
resetPomodoro,
setPomodoroDuration,
startFocusPomodoro,
startFocusPomodoroUnlessRunning,
tickPomodoro,
togglePomodoro,
type PomodoroState,
Expand Down Expand Up @@ -147,7 +147,16 @@
}

function startFocusTimer() {
pomodoroState = startFocusPomodoro(focusDurationSeconds);
const nextState = startFocusPomodoroUnlessRunning(
pomodoroState,
focusDurationSeconds,
);

if (nextState === pomodoroState) {
return;
}

pomodoroState = nextState;
syncInterval();
}

Expand Down
25 changes: 25 additions & 0 deletions src/lib/pomodoro/timer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
resetPomodoro,
setPomodoroDuration,
startFocusPomodoro,
startFocusPomodoroUnlessRunning,
tickPomodoro,
togglePomodoro,
} from "$lib/pomodoro/timer";
Expand Down Expand Up @@ -38,6 +39,30 @@ describe("pomodoro timer state", () => {
});
});

it("does not restart focus when the timer is already running", () => {
const state = {
remainingSeconds: 10 * 60,
durationSeconds: FOCUS_DURATION_SECONDS,
running: true,
};

expect(startFocusPomodoroUnlessRunning(state)).toBe(state);
});

it("starts focus from the full duration when the timer is not running", () => {
expect(
startFocusPomodoroUnlessRunning({
remainingSeconds: 10 * 60,
durationSeconds: FOCUS_DURATION_SECONDS,
running: false,
}),
).toEqual({
remainingSeconds: FOCUS_DURATION_SECONDS,
durationSeconds: FOCUS_DURATION_SECONDS,
running: true,
});
});

it("uses custom focus durations", () => {
const durationSeconds = 10 * 60;

Expand Down
11 changes: 11 additions & 0 deletions src/lib/pomodoro/timer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,17 @@ export function startFocusPomodoro(
};
}

export function startFocusPomodoroUnlessRunning(
state: PomodoroState,
durationSeconds = FOCUS_DURATION_SECONDS,
): PomodoroState {
if (state.running) {
return state;
}

return startFocusPomodoro(durationSeconds);
}

export function setPomodoroDuration(
state: PomodoroState,
durationSeconds: number,
Expand Down