Combine routines (ENG-9) phase 4: UI surfaces

- Plan → Week schedule: inline per-day management. A populated weekday
  shows always-visible routine sub-rows with an inline ✕ (removes; drops
  the day key on the last one) and a + Add routine action (single-pick
  append; already-added routines disabled). An empty day stays one
  tappable row → the first-routine picker. Day header shows an "N
  routines" hint. DayAssign is now the empty-day / single-pick sheet only;
  new dayAddRoutineSheet does the append.
- Workout header ⋮: "Add routine" is the first item; Cards / List /
  Compact move to a nested "Layout" sheet. addRoutineToSessionSheet
  appends the picked routine's entries (each stamped with its rid),
  extends s.active.routineIds, re-derives the name, toasts; a routine
  already in the session or with no exercises is disabled + tagged.
  s.active.cur is left where it is.
- History WorkoutDetail: a combined workout's entries are grouped into
  per-routine sections in merge order, each with a glyph+name /
  "N sets · volume" subheader. A legacy single-routine workout renders
  flat, exactly as before.
- Home today card: title is the derived session name (done in phase 3).

Tests: Plan inline management (week-start.test.jsx), the ⋮ Add-routine /
nested Layout menu (Workout.test.jsx), addRoutineToSessionSheet +
WorkoutDetail grouping (sheets.combine-ui.test.jsx). Six new UI strings
render English in translated packs — flagged by check-source-strings
(report-only) for a translation follow-up, as docs/COMBINE_ROUTINES.md
notes.

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 3dd2092a8d
commit c63ec2ca6c
6 files changed
+314 -30

No files matched your search

+26 -4
View File
@@ -2,7 +2,7 @@ import { useNavigate } from 'react-router-dom'
import { useStore } from '../store/useStore.js'
import { DAYN, weekOrder, weekStartOf, uid, exCount } from '../lib/format.js'
import { t } from '../lib/i18n.js'
import { dayAssignSheet, starterPlanSheet, planToolsSheet } from '../sheets.jsx'
import { dayAssignSheet, dayAddRoutineSheet, starterPlanSheet, planToolsSheet } from '../sheets.jsx'
import Icon from '../components/Icon.jsx'
import { Button } from '../components/ui.jsx'
import { tappable } from '../lib/use-sheet-keyboard.js'
@@ -31,6 +31,12 @@ export default function Plan() {
nav('/plan/r/' + r.id)
}
// Pull one routine off a weekday; drop the key when the day empties (never store []).
const removeFromDay = (d, rid) => update(s => {
const next = [].concat(s.week[d] || []).filter(id => id !== rid)
if (next.length) s.week[d] = next; else delete s.week[d]
})
return <>
<div className="hdr">
<div><h1>{t('Plan')}</h1><div className="sub">{t('Your weekly routine')}</div></div>
@@ -49,11 +55,27 @@ export default function Plan() {
<h4 className="sec">{t('Week schedule')}</h4>
<div className="list" style={{ display: 'flex', flexDirection: 'column' }}>
{weekOrder(weekStartOf(S)).map(d => {
const r = S.routines.find(x => x.id === S.week[d])
return <div key={d} className="item" {...tappable(() => dayAssignSheet(d))}>
const dayRoutines = [].concat(S.week[d] || []).map(id => S.routines.find(x => x.id === id)).filter(Boolean)
// An empty day stays one tappable row → pick its first routine (today's behaviour).
if (!dayRoutines.length) return <div key={d} className="item" {...tappable(() => dayAssignSheet(d))}>
<div className="grow"><div className="tt">{t(DAYN[d])}</div></div>
{r ? <span className="tag acc"><Icon name={glyphOf(r.emoji)} />{r.name}</span> : <span className="tag">{t('Rest')}</span>}
<span className="tag">{t('Rest')}</span>
<Icon name="chevronRight" className="chev" /></div>
// A populated day: always-visible routine sub-rows + inline ✕, then + Add routine.
return <div key={d} className="item" style={{ display: 'block', padding: '10px 14px' }}>
<div className="row between" style={{ marginBottom: 6 }}>
<div className="tt">{t(DAYN[d])}</div>
<div className="small dim">{t('{0} routines', dayRoutines.length)}</div>
</div>
{dayRoutines.map(r => <div key={r.id} className="row" style={{ gap: 8, padding: '4px 0 4px 8px' }}>
<span className="lrow-i" style={{ width: 26, height: 26, fontSize: 14 }}><Icon name={glyphOf(r.emoji)} /></span>
<div className="grow" style={{ minWidth: 0 }}><div className="tt" style={{ fontSize: 14 }}>{r.name}</div><div className="ss">{exCount(r.ex.length)}</div></div>
<button className="iconbtn sm" aria-label={t('Remove')} onClick={() => removeFromDay(d, r.id)}><Icon name="xmark" /></button>
</div>)}
<button className="btn ghost sm" style={{ marginTop: 4, marginLeft: 8 }} onClick={() => dayAddRoutineSheet(d)}>
<Icon name="plus" /> {t('Add routine')}
</button>
</div>
})}
</div>
</div><div>
+12 -3
View File
@@ -12,7 +12,7 @@ import { t, exerciseNameFor } from '../lib/i18n.js'
import { api } from '../lib/api.js'
import { insertionIndexAfterCurrentUnit, nextUnfinishedUnit, setProgressHighWater, supersetFlowStep, restAfterSet, restOnRecheck, restSecFor } from '../lib/supersetFlow.js'
import Media from '../components/Media.jsx'
import { startFlow, exercisePicker, exConfigSheet, exerciseDetailSheet, finishWorkout, workoutCompleteSheet, confirmSheet, exerciseNoteSheet, sessionNoteSheet, swapActiveWorkoutExercise, barWeightSheet, menuSheet, effortPickerSheet, exerciseHistorySheet } from '../sheets.jsx'
import { startFlow, exercisePicker, exConfigSheet, exerciseDetailSheet, finishWorkout, workoutCompleteSheet, confirmSheet, exerciseNoteSheet, sessionNoteSheet, swapActiveWorkoutExercise, barWeightSheet, menuSheet, effortPickerSheet, exerciseHistorySheet, addRoutineToSessionSheet } from '../sheets.jsx'
import { effortColor } from '../lib/effort.js'
import Icon from '../components/Icon.jsx'
import { Button, Check, NumberField } from '../components/ui.jsx'
@@ -556,14 +556,23 @@ function ActiveWorkout() {
// (Settings → During a workout → Workout view). It writes s.active.workoutView, which the
// render above prefers over S.workoutView.
const setWorkoutView = v => update(s => { if (s.active) s.active.workoutView = v })
const openViewMenu = () => menuSheet({
title: t('Workout view'),
const LAYOUT_LABEL = { cards: t('Cards'), list: t('List'), compact: t('Compact') }
const openLayoutMenu = () => menuSheet({
title: t('Layout'),
items: [
{ icon: 'clipboard', label: t('Cards'), on: workoutView === 'cards', onClick: () => setWorkoutView('cards') },
{ icon: 'list', label: t('List'), on: workoutView === 'list', onClick: () => setWorkoutView('list') },
{ icon: 'minimize', label: t('Compact'), on: workoutView === 'compact', onClick: () => setWorkoutView('compact') },
],
})
// The header ⋮: bring another routine into the session, then the layout switch nested a
// level down (it used to be the whole menu).
const openViewMenu = () => menuSheet({
items: [
{ icon: 'plus', label: t('Add routine'), sub: t('Bring another routine into this session'), onClick: addRoutineToSessionSheet },
{ icon: 'list', label: t('Layout'), sub: LAYOUT_LABEL[workoutView] || LAYOUT_LABEL.cards, onClick: openLayoutMenu },
],
})
const onSwipePointerDown = event => {
if (swipe.current || (event.pointerType && event.pointerType !== 'touch' && event.pointerType !== 'pen')) return
if (event.target.closest?.(SWIPE_IGNORED_TARGETS)) return
+20 -10
View File
@@ -78,6 +78,7 @@ vi.mock('../sheets.jsx', () => ({
sessionNoteSheet: vi.fn(),
effortPickerSheet: mocks.effortPickerSheet,
exerciseHistorySheet: mocks.exerciseHistorySheet,
addRoutineToSessionSheet: vi.fn(),
}))
vi.mock('../components/Media.jsx', () => ({ default: () => null }))
// api.js reads navigator.userAgent at module scope. This file installs its own DOM inside the
@@ -1157,21 +1158,30 @@ describe('workout view header menu', () => {
}
const item = (menu, label) => menu.items.filter(Boolean).find(it => it.label === label)
it('offers the three layouts and marks the running session current', async () => {
await mount([exercise('plain-bench', [false])], 0, { active: { workoutView: 'list' } })
// The header ⋮ now leads with "Add routine"; the layouts moved to a nested "Layout" sheet.
const openLayout = async menu => {
await act(async () => { item(menu, 'Layout').onClick() })
return mocks.menuSheet.mock.calls.at(-1)[0]
}
it('leads with Add routine, then a Layout sheet with the three layouts marked current', async () => {
await mount([exercise('plain-bench', [false])], 0, { active: { workoutView: 'list', routineIds: [] } })
const menu = await openMenu()
expect(menu.items.filter(Boolean).map(it => it.label)).toEqual(['Cards', 'List', 'Compact'])
expect(item(menu, 'List').on).toBe(true)
expect(item(menu, 'Cards').on).toBe(false)
expect(item(menu, 'Compact').on).toBe(false)
expect(menu.items.filter(Boolean).map(it => it.label)).toEqual(['Add routine', 'Layout'])
expect(item(menu, 'Layout').sub).toBe('List')
const layout = await openLayout(menu)
expect(layout.items.filter(Boolean).map(it => it.label)).toEqual(['Cards', 'List', 'Compact'])
expect(item(layout, 'List').on).toBe(true)
expect(item(layout, 'Cards').on).toBe(false)
})
it('writes the pick onto s.active without touching the global default', async () => {
await mount([exercise('plain-bench', [false])], 0, { workoutView: 'cards', active: { workoutView: 'cards' } })
it('writes the layout pick onto s.active without touching the global default', async () => {
await mount([exercise('plain-bench', [false])], 0, { workoutView: 'cards', active: { workoutView: 'cards', routineIds: [] } })
const menu = await openMenu()
await act(async () => { item(menu, 'Compact').onClick() })
const layout = await openLayout(await openMenu())
await act(async () => { item(layout, 'Compact').onClick() })
expect(mocks.S.active.workoutView).toBe('compact')
expect(mocks.S.workoutView).toBe('cards')
+41 -1
View File
@@ -46,7 +46,7 @@ vi.mock('./MobileOnboarding.jsx', () => ({ ConnectSheet: () => null }))
vi.mock('../sheets.jsx', () => ({
starterPlanSheet: vi.fn(), confirmSheet: vi.fn(), importFromApp: vi.fn(),
importFromHevy: vi.fn(), equipmentProfileSheet: vi.fn(),
dayAssignSheet: vi.fn(), planToolsSheet: vi.fn(),
dayAssignSheet: vi.fn(), dayAddRoutineSheet: vi.fn(), planToolsSheet: vi.fn(),
}))
globalThis.__APP_VERSION__ ??= 'test'
@@ -118,3 +118,43 @@ describe('Plan — the week schedule follows the setting', () => {
expect(rows[1].textContent).not.toContain('Push')
})
})
describe('Plan — inline per-day routine management (combine routines)', () => {
const mount = () => act(() => root.render(<Plan />))
const dayContainer = name => [...host.querySelectorAll('.item')].find(el => el.querySelector('.tt')?.textContent === name)
beforeEach(() => {
mocks.S.routines = [
{ id: 'r1', name: 'Push', emoji: null, ex: [{ id: 'a' }, { id: 'b' }] },
{ id: 'r2', name: 'Core', emoji: null, ex: [{ id: 'c' }] },
]
})
it('renders a sub-row per routine on a populated day, with the count hint', () => {
mocks.S.week = { 1: ['r1', 'r2'] }
mount()
const mon = dayContainer('Monday')
expect(mon.textContent).toContain('Push')
expect(mon.textContent).toContain('Core')
expect(mon.textContent).toContain('2 routines')
})
it('✕ removes a routine, and drops the day key on the last removal', () => {
mocks.S.week = { 1: ['r1', 'r2'] }
mount()
const removeButtons = () => [...dayContainer('Monday').querySelectorAll('button[aria-label="Remove"]')]
act(() => { removeButtons()[1].dispatchEvent(new Event('click', { bubbles: true })) })
expect(mocks.S.week[1]).toEqual(['r1'])
mount()
act(() => { removeButtons()[0].dispatchEvent(new Event('click', { bubbles: true })) })
expect(mocks.S.week).not.toHaveProperty('1')
})
it('an empty day stays one tappable row', () => {
mocks.S.week = {}
mount()
const tue = dayContainer('Tuesday')
expect(tue.textContent).toContain('Rest')
expect(tue.querySelectorAll('button[aria-label="Remove"]').length).toBe(0)
})
})