@@ -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