Skip to content

refactor: replace timer state with Zustand store#77

Merged
hyldmo merged 10 commits intomainfrom
hyldmo/rethink-timer-state
Apr 5, 2026
Merged

refactor: replace timer state with Zustand store#77
hyldmo merged 10 commits intomainfrom
hyldmo/rethink-timer-state

Conversation

@hyldmo
Copy link
Copy Markdown
Owner

@hyldmo hyldmo commented Apr 5, 2026

Summary

  • Replace RestTimerContext + useTimerState reducer + ref-based coordination with a single Zustand store (useWorkoutSessionStore)
  • Fix rest timer showing the next set instead of the one just completed (cursor now stays on confirmed set during rest, advances on dismiss)
  • Fix cursor drift when exiting/entering timer mode (store persists across navigations)
  • Extract duplicated SET_TYPE_STYLES/SET_TYPE_COLORS constants to src/lib/workouts/constants.ts

Test plan

  • yarn typecheck passes
  • yarn test passes (129 tests, 25 new store unit tests)
  • yarn build succeeds
  • Checklist mode: confirm set → rest timer in nav → dismiss → clears
  • Timer mode: start → done → rest shows completed set → next set → advances
  • Superset: A1 → no rest, cursor to B1, set timer starts → B1 → rest countdown
  • Exit/enter timer mode preserves position
  • Session complete → store resets, nav widget clears

🤖 Generated with Claude Code

Single Zustand store replaces RestTimerContext + useTimerState reducer +
ref-based coordination. Fixes rest timer showing wrong set and cursor
drift when exiting/entering timer mode.

- Extract SET_TYPE_STYLES/SET_TYPE_COLORS to shared constants
- Remove RestTimerProvider wrapper from RootLayout
- RestTimer nav widget reads from store directly
- TimerMode reads queue/cursor/rest from store (no local reducer)
- confirmSet() keeps cursor on completed set during rest
- dismissRest() advances cursor to next pending
- 25 unit tests for store actions

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
@github-actions
Copy link
Copy Markdown

github-actions bot commented Apr 5, 2026

Preview deployment

URL https://hyldmo-rethink-timer-state.macromaxxing.pages.dev
Branch hyldmo/rethink-timer-state
Commit afd43e4

hyldmo and others added 7 commits April 5, 2026 14:21
Subscribing to the entire store object caused useEffect deps to change
on every state update, triggering infinite re-renders (React error 185).

WorkoutSessionPage now selects individual actions. TimerMode selects
reactive state slices and uses getState() for imperative action calls.

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
Compute remaining locally from rest.endAt with 100ms interval instead
of reading the 1-second-precision store value.

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
Store no longer ticks — just stores rest.endAt. Consumers derive
remaining locally. Notification fires via a single setTimeout.
Removes remaining, _completedRef, _intervalId, _timeoutId fields
and the startTicking/clearTimers machinery.

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
Single hook returns `Date.now() - timestamp` in ms. Callers negate
and divide for countdown seconds. Removes useCountdown.

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
Uses numux -p to run check:lint, check:typecheck, and check:test in
parallel. Updated CLAUDE.md to document the command and instruct
always using it for verification.

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
@hyldmo hyldmo force-pushed the hyldmo/rethink-timer-state branch from 87317ec to e1baeee Compare April 5, 2026 12:43
The typecheck script now chains tsc calls directly. check:typecheck
delegates to it. concurrently is no longer needed.

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
@hyldmo hyldmo force-pushed the hyldmo/rethink-timer-state branch from e1baeee to bd1298d Compare April 5, 2026 12:50
Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
@hyldmo hyldmo merged commit 46158dc into main Apr 5, 2026
3 checks passed
@hyldmo hyldmo deleted the hyldmo/rethink-timer-state branch April 5, 2026 13:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant