Repository navigation
Synchronize selected routine schedule times - #84
Merged
rd-code-23 merged 1 commit intoAug 30, 2026
Merged
rd-code-23 merged 1 commit into
rd-code-23 merged 1 commit into
Conversation
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
Adds shared-time behavior to the routine schedule editor and moves its correlated state transitions into a reducer.
User behavior
Why useReducer was used
The schedule editor has three pieces of state that must stay consistent: which days are selected, the time assigned to each day, and whether selected days share one time. These values are not independent. For example, selecting a day may also need to assign a time, and changing one time may need to update several days.
Using separate useState calls made one user action update multiple state values through separate setters. That worked, but it spread the rules across several nested functions and allowed temporary or future inconsistencies such as a selected day without a time.
useReducer treats each interaction as one explicit action:
Each action receives the complete previous state and returns one complete next state. This keeps related updates atomic and puts the schedule rules in one testable place. The component is left responsible for rendering controls and dispatching actions rather than implementing business rules.
Why not Zustand
This is temporary state used only while editing the schedule modal. It should be discarded when the user cancels. Making it global would increase its lifetime and require extra cleanup. Zustand may be useful later for truly shared application state, but it is unnecessary for local modal edits.
Reducer structure
The reducer cases stay short and delegate transformations to pure helper functions:
The editor uses numeric dayOfWeek values instead of arbitrary strings, and every day always has a valid default time.
Tests
Dependency
This PR is stacked on PR #83, which adds the schedule modal UI. Once #83 merges, this PR can be rebased or retargeted to main.