Combine routines (ENG-9) phase 3: start-flow wiring + resolver call sites

startFlow / beginWorkout now take string | string[] | null and route
through buildCombinedEntries; callers pass [r.id], effectiveRoutineIds(...)
or [] as appropriate. Every effectiveRoutine(S,iso) render site that
showed one routine now iterates effectiveRoutines / checks
effectiveRoutineIds.

- sheets.jsx: beginWorkout / beginBackfill write s.active.routineIds +
  derived name, no routineId / excludeFromProgression; swapTo resolves the
  slot's routine from its entry rid and carries rid onto the replacement;
  DayOverride / Calendar use the plural resolver (dayPlan stays scalar —
  overriding a combined date collapses it, per spec §8); DayAssign writes a
  one-element list.
- active-exercise-swap.js: split-insert carries current.rid like it carries sg.
- Workout.jsx: StartChooser id-set exclusion + startFlow(list); add-exercise
  and progression-settings resolve the routine from the current entry's rid
  and stamp rid on a freehand add.
- TabBar / Home: onStart(effectiveRoutineIds(...)); Home plannedPerWeek
  counts scheduled days not routines; today card name joins the day's
  routines.
- mobile.js buildReminderNotifications: names all of a combined day's
  routines, or a count past two.
- RoutineEdit delete-cleanup pulls the id from each week list, drops an
  emptied key. api/server.js effectiveRoutineId reads the first of the list.

Tests: sheets.combine.test.jsx (beginWorkout with a routine-id list);
mobile.test.js combined-day reminder. Existing suites stay green on the
tolerant-reader path.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01JVbWJtoyQU4WgwFR4eAKgy
This commit is contained in:
HenryandClaude Sonnet 5 committed 2026-09-06 19:27:24 +01:00
1 parent 8b917b6331
commit 3dd2092a8d
10 files changed
+190 -62

No files matched your search

+3
View File
@@ -37,6 +37,9 @@ export function swapActiveExercise(active, index, replacement, {
const insertAt = keepGroup ? index + 1 : (unit.length > 1 ? unit.at(-1) + 1 : index + 1)
active.entries.splice(insertAt, 0, {
...replacement,
// A swap does not change which routine the slot belongs to — carry its `rid` the same
// way `sg` is carried, so a combined session's WorkoutDetail groups stay contiguous.
...(current.rid ? { rid: current.rid } : {}),
...(keepGroup ? { sg: current.sg } : {})
})
active.cur = insertAt
+6 -5
View File
@@ -11,7 +11,7 @@
// web bundles; the Capacitor plugins are only ever imported behind it.
import { t } from './i18n-core.js'
import { isoOf, todayISO } from './format.js'
import { effectiveRoutineId } from './history.js'
import { effectiveRoutineIds } from './history.js'
export const MOBILE = import.meta.env.VITE_MOBILE === '1'
@@ -108,16 +108,17 @@ export function buildReminderNotifications(S, now = new Date()) {
day.setDate(date.getDate() + offset)
const iso = isoOf(day)
if (completed.has(iso)) continue
const rid = effectiveRoutineId(state, iso)
const routine = routines.find(x => x.id === rid)
if (!routine) continue
// A weekday can hold several routines; name them all, or fall back to a count.
const dayRoutines = effectiveRoutineIds(state, iso).map(id => routines.find(x => x.id === id)).filter(Boolean)
if (!dayRoutines.length) continue
const label = dayRoutines.length <= 2 ? dayRoutines.map(r => r.name).join(' + ') : t('{0} routines', dayRoutines.length)
const at = new Date(day)
at.setHours(hour, minute, 0, 0)
if (at <= now) continue
notifications.push({
id: REMINDER_ID_BASE + offset,
title: t('Workout day'),
body: t('{0} is on the plan today — let’s go!', routine.name),
body: t('{0} is on the plan today — let’s go!', label),
schedule: { at, allowWhileIdle: true },
})
}
+15
View File
@@ -59,4 +59,19 @@ describe('buildReminderNotifications', () => {
expect(notifications.some(n => iso(n.schedule.at) === iso(now))).toBe(false)
expect(notifications.some(n => iso(n.schedule.at) === iso(new Date(2026, 5, 8)))).toBe(true)
})
it('names both routines of a combined day, and reads a legacy scalar day the same', () => {
const now = new Date(2026, 5, 1, 7, 0) // Monday
const combined = buildReminderNotifications(state({ week: { 1: ['push', 'pull'] } }), now)[0]
expect(combined.body).toContain('Push + Pull')
const legacy = buildReminderNotifications(state({ week: { 1: 'push' } }), now)[0]
expect(legacy.body).toContain('Push')
})
it('falls back to a count for three or more routines on one day', () => {
const now = new Date(2026, 5, 1, 7, 0)
const n = buildReminderNotifications(state({ week: { 1: ['push', 'pull', 'legs'] } }), now)[0]
expect(n.body).toContain('3 routines')
})
})