Skip to content

Commit 036d24d

Browse files
hyldmoclaude
andauthored
fix: sync nav timer with timer mode and checklist mode (#79)
Nav RestTimer now shows set elapsed when a set timer is active, matching what TimerMode displays. Session page passes startedAt to the store so session elapsed works in checklist mode too. Store init() preserves existing rest timers. Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 62b0b08 commit 036d24d

File tree

3 files changed

+27
-6
lines changed

3 files changed

+27
-6
lines changed

src/features/workouts/WorkoutSessionPage.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,11 +99,11 @@ export function WorkoutSessionPage() {
9999
{ enabled: !!effectiveSessionId }
100100
)
101101

102-
// Signal rest timer that a session is active (sessionId only — elapsed activates from TimerMode)
102+
// Signal rest timer that a session is active
103103
const isCompleteSession = !!sessionQuery.data?.completedAt
104104
useEffect(() => {
105105
if (sessionQuery.data && !isCompleteSession) {
106-
storeSetSession({ id: sessionQuery.data.id })
106+
storeSetSession({ id: sessionQuery.data.id, startedAt: sessionQuery.data.startedAt })
107107
} else if (isCompleteSession) {
108108
storeReset()
109109
}

src/features/workouts/components/RestTimer.tsx

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,14 @@ export const RestTimer: FC = () => {
99
const sessionId = useWorkoutSessionStore(s => s.sessionId)
1010
const sessionStartedAt = useWorkoutSessionStore(s => s.sessionStartedAt)
1111
const rest = useWorkoutSessionStore(s => s.rest)
12+
const setTimer = useWorkoutSessionStore(s => s.active?.setTimer)
1213
const dismissRest = useWorkoutSessionStore(s => s.dismissRest)
1314
const navigate = useNavigate()
14-
const isRunning = rest !== null
15-
const elapsed = useElapsedTimer(!isRunning && sessionStartedAt ? sessionStartedAt : null)
15+
const isResting = rest !== null
16+
const setTimerActive = setTimer && !setTimer.isPaused ? setTimer.startedAt : null
17+
const sessionElapsedTimestamp = isResting || setTimerActive ? null : sessionStartedAt
18+
const elapsed = useElapsedTimer(sessionElapsedTimestamp)
19+
const setElapsedMs = useElapsedTimer(isResting ? null : setTimerActive)
1620
const remaining = -useElapsedTimer(rest?.endAt ?? null) / 1000
1721

1822
const goToTimer = () => {
@@ -52,6 +56,20 @@ export const RestTimer: FC = () => {
5256
)
5357
}
5458

59+
// Active set timer — show set elapsed (matches timer mode)
60+
if (sessionId && setTimerActive) {
61+
return (
62+
<button
63+
type="button"
64+
className="flex items-center gap-1.5 rounded-sm border border-edge px-2 py-1 text-ink-faint hover:text-accent"
65+
onClick={goToTimer}
66+
>
67+
<Dumbbell className="size-3.5" />
68+
<span className="font-mono text-sm tabular-nums">{formatTimer(setElapsedMs / 1000)}</span>
69+
</button>
70+
)
71+
}
72+
5573
// Session active with timer activated — show elapsed time
5674
if (sessionId && sessionStartedAt) {
5775
return (

src/features/workouts/store/useWorkoutSessionStore.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,14 +161,17 @@ export const useWorkoutSessionStore = create<WorkoutSessionStore>((set, get) =>
161161
},
162162

163163
init: (sessionId, startedAt, sets) => {
164-
clearNotificationTimeout()
164+
const existing = get()
165+
// Preserve rest timer if one is running (e.g., started in checklist mode)
166+
if (!existing.rest) clearNotificationTimeout()
165167
const cursor = findNextPending(sets, 0, [])
166168
set({
167169
...INITIAL_STATE,
168170
sessionId,
169171
sessionStartedAt: startedAt,
170172
queue: sets,
171-
active: loadActive(sets, cursor)
173+
active: loadActive(sets, cursor),
174+
rest: existing.rest
172175
})
173176
},
174177

0 commit comments

Comments
 (0)