diff --git a/api/server.js b/api/server.js
index 675a5d8..a5b35f1 100644
--- a/api/server.js
+++ b/api/server.js
@@ -204,12 +204,13 @@ function cancelRestTimer(userId) {
// "Workout planned today" reminder — one per user per day, at their chosen time.
// Duplicated (not imported) from frontend/src/lib/history.js effectiveRoutineId — tiny pure helper, not worth sharing across the two runtimes.
+// A weekday can hold a routine-id list (combine routines); the reminder only needs the first.
function effectiveRoutineId(S, iso) {
const ov = S.dayPlan?.[iso];
if (ov === 'rest') return null;
if (ov && S.routines?.some(r => r.id === ov)) return ov;
const wd = new Date(iso + 'T12:00:00').getDay();
- return S.week?.[wd] || null;
+ return [].concat(S.week?.[wd] || []).find(id => S.routines?.some(r => r.id === id)) || null;
}
// Computes "now" in an arbitrary IANA zone (e.g. "Europe/Lisbon") instead of the server's own —
// each user's reminder fires by their own clock, wherever they and their phone actually are.
diff --git a/frontend/src/components/TabBar.jsx b/frontend/src/components/TabBar.jsx
index 97d27db..d33c7a2 100644
--- a/frontend/src/components/TabBar.jsx
+++ b/frontend/src/components/TabBar.jsx
@@ -1,6 +1,6 @@
import { useLocation, useNavigate } from 'react-router-dom'
import { useStore } from '../store/useStore.js'
-import { effectiveRoutine } from '../lib/history.js'
+import { effectiveRoutineIds, effectiveRoutines } from '../lib/history.js'
import { todayISO } from '../lib/format.js'
import { t } from '../lib/i18n.js'
import Icon from './Icon.jsx'
@@ -17,8 +17,9 @@ export default function TabBar({ onStart }) {
const startWorkout = () => {
if (!S.active) {
- const r = effectiveRoutine(S, todayISO())
- if (r && r.ex.length) { onStart(r.id); return }
+ // A weekday can hold several routines; start the combined session if any of them has
+ // exercises, otherwise fall through to the picker.
+ if (effectiveRoutines(S, todayISO()).some(r => r.ex.length)) { onStart(effectiveRoutineIds(S, todayISO())); return }
}
nav('/workout')
}
diff --git a/frontend/src/lib/active-exercise-swap.js b/frontend/src/lib/active-exercise-swap.js
index 114dbb9..57fc945 100644
--- a/frontend/src/lib/active-exercise-swap.js
+++ b/frontend/src/lib/active-exercise-swap.js
@@ -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
diff --git a/frontend/src/lib/mobile.js b/frontend/src/lib/mobile.js
index 8af59f8..f2cc584 100644
--- a/frontend/src/lib/mobile.js
+++ b/frontend/src/lib/mobile.js
@@ -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 },
})
}
diff --git a/frontend/src/lib/mobile.test.js b/frontend/src/lib/mobile.test.js
index c43a395..eeef274 100644
--- a/frontend/src/lib/mobile.test.js
+++ b/frontend/src/lib/mobile.test.js
@@ -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')
+ })
})
\ No newline at end of file
diff --git a/frontend/src/sheets.combine.test.jsx b/frontend/src/sheets.combine.test.jsx
new file mode 100644
index 0000000..0dcec74
--- /dev/null
+++ b/frontend/src/sheets.combine.test.jsx
@@ -0,0 +1,69 @@
+// @vitest-environment happy-dom
+import { act } from 'react'
+import { beforeEach, describe, expect, it } from 'vitest'
+import { beginWorkout } from './sheets.jsx'
+import { EXDB } from './lib/exercises.js'
+import { DEF, useStore } from './store/useStore.js'
+import { useUI } from './store/useUI.js'
+
+const clone = v => JSON.parse(JSON.stringify(v))
+const ids = EXDB.filter(e => e.bp !== 'cardio').slice(0, 3).map(e => e.id)
+
+function install(routines, week = {}) {
+ const S = clone(DEF)
+ S.routines = routines
+ S.week = week
+ S.active = null
+ S.workouts = []
+ useStore.setState({ S, user: null })
+}
+
+beforeEach(() => {
+ localStorage.clear()
+ useUI.setState({ sheets: [] })
+ install([
+ { id: 'strength', name: 'Strength', emoji: '🏋️', prog: 'off', ex: [{ id: ids[0], sets: 3, reps: 5, weight: 60 }] },
+ { id: 'core', name: 'Core', emoji: '🧘', prog: 'off', ex: [{ id: ids[1], sets: 3, reps: 12, weight: 0 }, { id: ids[2], sets: 3, reps: 10, weight: 0 }] },
+ { id: 'rehab', name: 'Rehab', emoji: '🩹', excludeFromProgression: true, ex: [{ id: ids[1], sets: 2, reps: 15, weight: 5 }] },
+ ])
+})
+
+describe('beginWorkout with a routine-id list', () => {
+ it('concatenates the routines’ entries in order, stamps rid, derives the name', () => {
+ act(() => beginWorkout(['strength', 'core'], null))
+ const a = useStore.getState().S.active
+ expect(a.routineIds).toEqual(['strength', 'core'])
+ expect(a.name).toBe('Strength + Core')
+ expect(a.entries.map(e => e.rid)).toEqual(['strength', 'core', 'core'])
+ expect(a).not.toHaveProperty('routineId')
+ expect(a).not.toHaveProperty('excludeFromProgression')
+ })
+
+ it('a single-element list is an ordinary single-routine session', () => {
+ act(() => beginWorkout(['strength'], null))
+ const a = useStore.getState().S.active
+ expect(a.routineIds).toEqual(['strength'])
+ expect(a.name).toBe('Strength')
+ expect(a.entries.every(e => e.rid === 'strength')).toBe(true)
+ })
+
+ it('an empty list is a freestyle session — no entries, no rid', () => {
+ act(() => beginWorkout([], null))
+ const a = useStore.getState().S.active
+ expect(a.routineIds).toEqual([])
+ expect(a.name).toBe('Freestyle')
+ expect(a.entries).toEqual([])
+ })
+
+ it('carries a merged excluded routine’s per-entry noProg', () => {
+ act(() => beginWorkout(['strength', 'rehab'], null))
+ const a = useStore.getState().S.active
+ expect(a.entries.find(e => e.rid === 'rehab').noProg).toBe(true)
+ expect(a.entries.find(e => e.rid === 'strength').noProg).toBeUndefined()
+ })
+
+ it('drops an unknown id and de-dupes a repeat (first wins)', () => {
+ act(() => beginWorkout(['core', 'gone', 'core'], null))
+ expect(useStore.getState().S.active.routineIds).toEqual(['core'])
+ })
+})
diff --git a/frontend/src/sheets.jsx b/frontend/src/sheets.jsx
index 2ca09d2..8af095f 100644
--- a/frontend/src/sheets.jsx
+++ b/frontend/src/sheets.jsx
@@ -4,7 +4,7 @@ import { useUI } from './store/useUI.js'
import { EXDB, EXIDX, BODYPARTS, isCardio, isBodyweightEq, allExercises, equipmentOf, smOf, matchExercise, exOr } from './lib/exercises.js'
import { activeProfile, exAvailable, ALL_EQUIPMENT, newProfile } from './lib/equipment.js'
import { fmtDate, fmtNum, fmtVol, fmtDur, durPart, todayISO, isoOf, uid, exCount, DAYN, DAYS, weekOrder, weekStartOf, weekDayOffset, MONTHS_LONG, ACCENTS } from './lib/format.js'
-import { lastEntryFor, bestWeightFor, bestWeightForEntry, buildSets, effectiveRoutineId, workoutVolume, setsDone, setsDoneActive, lastBW, supersetUnits, unitOf, setLabel, defaultConfig, cleanupSg, modeOf, effortOf, EFFORT, capEffort, stepEffort, isBw, isPerSide, sideReps, workSetsDone, applyIntensifierPlan, MAX_PLANNED_WARMUPS, NOTE_MAX } from './lib/history.js'
+import { lastEntryFor, bestWeightFor, bestWeightForEntry, buildSets, effectiveRoutineIds, workoutVolume, setsDone, setsDoneActive, lastBW, supersetUnits, unitOf, setLabel, defaultConfig, cleanupSg, modeOf, effortOf, EFFORT, capEffort, stepEffort, isBw, isPerSide, sideReps, workSetsDone, applyIntensifierPlan, MAX_PLANNED_WARMUPS, NOTE_MAX } from './lib/history.js'
import { usesBar, barWeightFor, defaultBarWeight, hasBarOverride } from './lib/bar.js'
import { toScale, rirOf, EFFORT_PRESETS, effortColor } from './lib/effort.js'
import { beep, vibrate } from './lib/sound.js'
@@ -35,6 +35,7 @@ import { swapActiveExercise } from './lib/active-exercise-swap.js'
import { useSheetKeyboard, useRevealActiveChip, tappable } from './lib/use-sheet-keyboard.js'
import { isFav, toggleFav, sortFavouritesFirst } from './lib/favourites.js'
import { buildSessionEntries } from './lib/session-start.js'
+import { buildCombinedEntries, deriveSessionName } from './lib/session-merge.js'
import { workoutsOn, backfillStart, backfillEnd, completeBackfill } from './lib/backfill.js'
const S = () => useStore.getState().S
@@ -950,20 +951,25 @@ export function swapActiveWorkoutExercise(index) {
picker.close()
const full = { ...cfg, id: ex.id }
const st = S()
+ const current = st.active?.entries?.[index]
+ if (!current) return
+ // A swap is an in-place substitution — routine identity is unchanged, so the replacement
+ // keeps the slot's own `rid` and reads its prescription from that routine (not a
+ // session-wide one). A slot with no `rid` is freestyle.
+ const slotRoutine = current.rid ? st.routines.find(r => r.id === current.rid) : null
+ const freestyle = !slotRoutine
// Same rows the add flow builds: last time's loads and, in a planned session, the
// prescription — swapping barbell for dumbbell bench must not start you at an empty bar.
- const freestyle = !st.active?.routineId
const step = modeOf(full) === 'reps' ? weightIncrement(full, st.unit) : defaultIncrement(ex.id, st.unit)
- const plan = freestyle ? null : nextPrescription(st, full, st.routines.find(r => r.id === st.active.routineId))
+ const plan = freestyle ? null : nextPrescription(st, full, slotRoutine)
const built = buildSets(st, full, { step, ...(freestyle ? { preferLast: true } : {}), ...(plan?.kind === 'off' ? { useTarget: true } : {}) })
const replacement = {
id: ex.id,
target: { ...cfg },
plan,
- sets: applyIntensifierPlan(freestyle ? built : applyPrescription(built, plan, step), full)
+ sets: applyIntensifierPlan(freestyle ? built : applyPrescription(built, plan, step), full),
+ ...(current.rid ? { rid: current.rid } : {}),
}
- const current = S().active?.entries?.[index]
- if (!current) return
const apply = options => {
// A timed callback closes over entry/set indexes. Invalidate it, and the current rest,
@@ -1505,9 +1511,12 @@ function PlanImport({ bundle, close }) {
function DayOverride({ iso, close }) {
const st = useStore(s => s.S)
const wd = new Date(iso + 'T12:00:00').getDay()
- const weeklyR = st.routines.find(r => r.id === st.week[wd])
+ const weeklyNames = [].concat(st.week[wd] || []).map(id => st.routines.find(r => r.id === id)?.name).filter(Boolean)
const hasOvr = st.dayPlan[iso] !== undefined
- const effId = effectiveRoutineId(st, iso)
+ // A weekday can hold several routines; the per-date override stays single-pick, so picking
+ // one here collapses a combined day to it (docs/COMBINE_ROUTINES.md §8). The check marks
+ // show everything currently planned for the day.
+ const effIds = effectiveRoutineIds(st, iso)
const set = v => {
update(s => { if (!v) delete s.dayPlan[iso]; else s.dayPlan[iso] = v })
close()
@@ -1515,13 +1524,13 @@ function DayOverride({ iso, close }) {
}
return <>
{fmtDate(iso, true)}
-
{t('Weekly plan:')} {weeklyR ? weeklyR.name : t('Rest')}{hasOvr && · {t('changed for this day')}} {t('Sick, missed a day or want a different session? Pick what to train instead.')}
+
{t('Weekly plan:')} {weeklyNames.length ? deriveSessionName(weeklyNames) : t('Rest')}{hasOvr && · {t('changed for this day')}} {t('Sick, missed a day or want a different session? Pick what to train instead.')}
{st.routines.map(r =>
set(r.id))}>
{r.name}
{exCount(r.ex.length)}
- {effId === r.id && }
)}
-
set('rest'))}>
{t('Rest / skip this day')}
{effId === null && }
+ {effIds.includes(r.id) && }
)}
+
set('rest'))}>
{t('Rest / skip this day')}
{effIds.length === 0 && }
{hasOvr &&
set(''))}>
{t('Back to weekly plan')}
}
>
@@ -1530,15 +1539,18 @@ export const dayOverrideSheet = iso => ui().openSheet(close => s.S)
- const set = v => { update(s => { if (v) s.week[day] = v; else delete s.week[day] }); close() }
+ // A weekday holds a routine-id list; this single-pick sheet sets the day to exactly one
+ // routine (or rest). The inline per-day management on the Plan screen is what appends.
+ const cur = [].concat(st.week[day] || [])
+ const set = v => { update(s => { if (v) s.week[day] = [v]; else delete s.week[day] }); close() }
return <>