Skip to content

Commit 56fc1e2

Browse files
committed
fix format
1 parent 7fa8d2d commit 56fc1e2

2 files changed

Lines changed: 41 additions & 33 deletions

File tree

src/components/PomodoroTimer.tsx

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -130,15 +130,15 @@ const PomodoroTimer: React.FC<PomodoroTimerProps> = ({
130130
const now = Date.now();
131131
const msRemaining = Math.max(0, endTime - now);
132132
const secondsRemaining = Math.ceil(msRemaining / 1000);
133-
133+
134134
const duration = mode === "work" ? workDuration : breakDuration;
135135
// Calculate precise progress (0.0 to 1.0)
136136
// We use ms for the ring to be buttery smooth
137137
// Total duration in ms
138138
const durationMs = duration * 1000;
139139
// Progress acts inverted in the original code (remaining / total)
140140
const exactProgress = Math.min(1, Math.max(0, msRemaining / durationMs));
141-
141+
142142
setSmoothRemaining(secondsRemaining);
143143
setSmoothProgress(exactProgress);
144144

@@ -150,8 +150,15 @@ const PomodoroTimer: React.FC<PomodoroTimerProps> = ({
150150
animate();
151151

152152
return () => cancelAnimationFrame(animationFrameId);
153-
}, [isRunning, isPaused, endTime, mode, workDuration, breakDuration, storeRemainingTime]);
154-
153+
}, [
154+
isRunning,
155+
isPaused,
156+
endTime,
157+
mode,
158+
workDuration,
159+
breakDuration,
160+
storeRemainingTime,
161+
]);
155162

156163
// Keep 'now' updated for pause duration display (low freq is fine for this)
157164
useEffect(() => {
@@ -350,7 +357,7 @@ const PomodoroTimer: React.FC<PomodoroTimerProps> = ({
350357
// smoothProgress is 0..1 (remaining/total), but we want inverse for strokeDashoffset calc if we want it to shrink
351358
// The original code was: progress = remainingTime / duration
352359
// strokeDashoffset = circumference - progress * circumference
353-
360+
354361
// So if progress is 1 (full), offset is 0 (full ring).
355362
// If progress is 0 (empty), offset is circumference (empty ring).
356363
const strokeDashoffset = circumference - smoothProgress * circumference;

src/stores/pomodoro.ts

Lines changed: 29 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ export const usePomodoroStore = create<PomodoroState>()(
4747
lastTick: undefined,
4848
finishedSession: undefined,
4949
endTime: undefined, // New: track expected end time
50-
50+
5151
start: (taskId?: string) =>
5252
set((state) => {
5353
const now = Date.now();
@@ -60,20 +60,20 @@ export const usePomodoroStore = create<PomodoroState>()(
6060
mode: "work",
6161
currentTaskId: taskId,
6262
startTime: now,
63-
endTime: now + duration * 1000,
63+
endTime: now + duration * 1000,
6464
lastTick: now,
6565
};
6666
}),
6767

68-
pause: () =>
68+
pause: () =>
6969
set((state) => {
70-
// When pausing, we clear endTime because "real time" flow stops for the timer.
71-
// remainingTime is preserved.
72-
return {
73-
isPaused: true,
74-
pauseStart: Date.now(),
75-
endTime: undefined
76-
};
70+
// When pausing, we clear endTime because "real time" flow stops for the timer.
71+
// remainingTime is preserved.
72+
return {
73+
isPaused: true,
74+
pauseStart: Date.now(),
75+
endTime: undefined,
76+
};
7777
}),
7878

7979
resume: () =>
@@ -138,28 +138,28 @@ export const usePomodoroStore = create<PomodoroState>()(
138138
tick: () =>
139139
set((state) => {
140140
if (!state.isRunning || state.isPaused) return state;
141-
141+
142142
const now = Date.now();
143143
// If we somehow don't have an endTime (legacy state or bug), set it now
144144
if (!state.endTime) {
145-
return {
146-
...state,
147-
endTime: now + state.remainingTime * 1000,
148-
lastTick: now,
149-
};
145+
return {
146+
...state,
147+
endTime: now + state.remainingTime * 1000,
148+
lastTick: now,
149+
};
150150
}
151151

152152
const msRemaining = state.endTime - now;
153153
// Ceiling to keep 0.9s as "1s" remaining on UI until it truly hits 0
154154
const remainingSeconds = Math.max(0, Math.ceil(msRemaining / 1000));
155-
155+
156156
if (remainingSeconds > 0) {
157157
// Only update if changed to avoid unnecessary re-renders if called rapidly
158158
if (remainingSeconds !== state.remainingTime) {
159-
return {
160-
remainingTime: remainingSeconds,
161-
lastTick: now,
162-
};
159+
return {
160+
remainingTime: remainingSeconds,
161+
lastTick: now,
162+
};
163163
}
164164
return state;
165165
}
@@ -169,9 +169,9 @@ export const usePomodoroStore = create<PomodoroState>()(
169169
// Accurate start/end for history
170170
const durationSec =
171171
finishedMode === "work" ? state.workDuration : state.breakDuration;
172-
172+
173173
// Use stored endTime for exact record, or now if significantly off
174-
const exactEnd = state.endTime;
174+
const exactEnd = state.endTime;
175175
const calculatedStart = exactEnd - durationSec * 1000;
176176

177177
const finishedSession = {
@@ -181,11 +181,12 @@ export const usePomodoroStore = create<PomodoroState>()(
181181
};
182182

183183
const nextMode = state.mode === "work" ? "break" : "work";
184-
const nextDuration = nextMode === "work" ? state.workDuration : state.breakDuration;
185-
186-
// Start next session immediately from 'now'.
184+
const nextDuration =
185+
nextMode === "work" ? state.workDuration : state.breakDuration;
186+
187+
// Start next session immediately from 'now'.
187188
// (Optionally could be 'exactEnd' if we want zero gap, but 'now' is safer for user perception)
188-
189+
189190
return {
190191
mode: nextMode,
191192
remainingTime: nextDuration,
@@ -202,7 +203,7 @@ export const usePomodoroStore = create<PomodoroState>()(
202203
set((state) => ({
203204
workDuration: work,
204205
breakDuration: brk,
205-
// If not running, update display immediately.
206+
// If not running, update display immediately.
206207
// If running, don't change current session but next one will use new durations.
207208
remainingTime: !state.isRunning ? work : state.remainingTime,
208209
})),

0 commit comments

Comments
 (0)