Skip to content

Synchronize selected routine schedule times - #84

Merged
rd-code-23 merged 1 commit into
feature/routine-schedule-modal-uifrom
feature/routine-schedule-shared-time
Aug 30, 2026
Merged

rd-code-23 merged 1 commit into
feature/routine-schedule-modal-uifrom
feature/routine-schedule-shared-time

Conversation

@rd-code-23

Copy link
Copy Markdown
Owner

Summary

Adds shared-time behavior to the routine schedule editor and moves its correlated state transitions into a reducer.

User behavior

  • Use same time for selected days is enabled by default.
  • Selecting another day copies the current shared time.
  • Changing one selected day updates every selected day while shared time is enabled.
  • Turning shared time off lets each selected day keep a different time.
  • Turning shared time back on synchronizes selected days to the first selected time.

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:

  • day-toggled
  • time-changed
  • shared-time-toggled

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:

  • toggleDay
  • changeDayTime
  • synchronizeSelectedDayTimes
  • getFirstSelectedTime

The editor uses numeric dayOfWeek values instead of arbitrary strings, and every day always has a valid default time.

Tests

  • selecting a new day copies the shared time
  • shared mode updates all selected days
  • independent mode updates only the edited day
  • UI behavior verifies enabling and disabling shared time
  • all 44 web tests pass

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.

@rd-code-23
rd-code-23 merged commit 811c9fd into feature/routine-schedule-modal-ui Aug 30, 2026
1 check passed
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