refactor: replace timer state with Zustand store#77
Merged
Conversation
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]>
Preview deployment
|
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]>
87317ec to
e1baeee
Compare
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]>
e1baeee to
bd1298d
Compare
Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
RestTimerContext+useTimerStatereducer + ref-based coordination with a single Zustand store (useWorkoutSessionStore)SET_TYPE_STYLES/SET_TYPE_COLORSconstants tosrc/lib/workouts/constants.tsTest plan
yarn typecheckpassesyarn testpasses (129 tests, 25 new store unit tests)yarn buildsucceeds🤖 Generated with Claude Code