blob: 6a81e20a89edfcb7ea7395e0f7be56bb2a8d4191 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
|
import { create } from 'zustand';
export type TimerPhase = 'work' | 'short_break' | 'long_break';
export interface TimerTickPayload {
phase: TimerPhase;
remaining_secs: number;
total_secs: number;
session_count: number;
current_task_id: string | null;
}
interface TimerState {
phase: TimerPhase;
remainingSecs: number;
totalSecs: number;
running: boolean;
sessionCount: number;
currentTaskId: string | null;
setTimerTick: (payload: TimerTickPayload) => void;
setRunning: (running: boolean) => void;
}
export const useTimerStore = create<TimerState>((set) => ({
phase: 'work',
remainingSecs: 25 * 60,
totalSecs: 25 * 60,
running: false,
sessionCount: 0,
currentTaskId: null,
setTimerTick: (payload) =>
set({
phase: payload.phase,
remainingSecs: payload.remaining_secs,
totalSecs: payload.total_secs,
sessionCount: payload.session_count,
currentTaskId: payload.current_task_id,
}),
setRunning: (running) => set({ running }),
}));
|