Workout view: add a "compact" layout and a per-session ⋮ switcher
S.workoutView gains a third value, 'compact': the list layout with each
ExerciseBlock rendered `dense` — no media, tag chips ("Best:" included),
note lines, "Last time" recap, bar/plates chip or progression-guidance
line. Just the name, the ⋯ menu and the set rows. Everything stripped is
still on the ⋯ menu or is display-only.
- Settings → During a workout → Workout view is now a 3-way Segmented
(Cards / List / Compact).
- The workout header gains a ⋮ button (menuSheet) that writes
s.active.workoutView, overriding the layout for the running session.
- beginWorkout / beginBackfill snapshot S.workoutView onto s.active, and
the render prefers A.workoutView || S.workoutView — so changing the
saved default never disturbs a workout already in progress.
- 'Compact' added to all 14 locales; pt-BR inheritance fingerprint
regenerated (inherited 613 → 614).
cards / list behaviour is unchanged. Component tests in Workout.test.jsx,
Settings.workoutview.test.jsx and a new sheets.workoutview.test.jsx;
docs/LIST_VIEW.md rewritten to the shipped model.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_016QqZBhX7PVNsRqLhkTt9y3
This commit is contained in:
1 parent
5c2005e81f
commit
e7a4597478
22 files changed
+282
-23
No files matched your search
@@ -223,12 +223,14 @@ export default function Settings() {
|
||||
|
||||
{/* ---------- during a workout ---------- */}
|
||||
<Section title={t('During a workout')} footer={wakeOK ? t('The screen stays on while a workout is running, so you don’t have to unlock your phone between sets.') : null}>
|
||||
{/* One exercise at a time (cards with Prev/Next) or the whole session stacked as a
|
||||
scrollable list. Legacy/unknown values read as cards. */}
|
||||
{/* One exercise at a time (cards with Prev/Next), the whole session stacked as a
|
||||
scrollable list, or that list stripped to just names and set rows (compact).
|
||||
Legacy/unknown values read as cards. The running session can override this from
|
||||
the workout header's ⋮ menu without changing this default. */}
|
||||
<Row icon="list" iconTint="var(--blue)" title={t('Workout view')}>
|
||||
<Segmented className="seg-inline"
|
||||
options={[{ value: 'cards', label: t('Cards') }, { value: 'list', label: t('List') }]}
|
||||
value={S.workoutView === 'list' ? 'list' : 'cards'}
|
||||
options={[{ value: 'cards', label: t('Cards') }, { value: 'list', label: t('List') }, { value: 'compact', label: t('Compact') }]}
|
||||
value={['list', 'compact'].includes(S.workoutView) ? S.workoutView : 'cards'}
|
||||
onChange={v => update(s => { s.workoutView = v })} />
|
||||
</Row>
|
||||
{/* The lean workout screen keeps the sets and one "more" button per exercise; each switch
|
||||
|
||||
@@ -67,15 +67,20 @@ const mount = () => act(() => root.render(<Settings />))
|
||||
const segButton = label => [...host.querySelectorAll('.seg button')].find(b => b.textContent === label)
|
||||
|
||||
describe('Settings — workout view', () => {
|
||||
it('offers Cards / List and writes workoutView to the store', () => {
|
||||
it('offers Cards / List / Compact and writes workoutView to the store', () => {
|
||||
mount()
|
||||
expect(segButton('Cards')).toBeTruthy()
|
||||
expect(segButton('List')).toBeTruthy()
|
||||
expect(segButton('Compact')).toBeTruthy()
|
||||
expect(segButton('Cards').getAttribute('aria-pressed')).toBe('true')
|
||||
act(() => { segButton('List').click() })
|
||||
expect(mocks.S.workoutView).toBe('list')
|
||||
mount()
|
||||
expect(segButton('List').getAttribute('aria-pressed')).toBe('true')
|
||||
act(() => { segButton('Compact').click() })
|
||||
expect(mocks.S.workoutView).toBe('compact')
|
||||
mount()
|
||||
expect(segButton('Compact').getAttribute('aria-pressed')).toBe('true')
|
||||
act(() => { segButton('Cards').click() })
|
||||
expect(mocks.S.workoutView).toBe('cards')
|
||||
})
|
||||
@@ -85,5 +90,6 @@ describe('Settings — workout view', () => {
|
||||
mount()
|
||||
expect(segButton('Cards').getAttribute('aria-pressed')).toBe('true')
|
||||
expect(segButton('List').getAttribute('aria-pressed')).toBe('false')
|
||||
expect(segButton('Compact').getAttribute('aria-pressed')).toBe('false')
|
||||
})
|
||||
})
|
||||
@@ -65,7 +65,11 @@ function Elapsed({ start }) {
|
||||
}
|
||||
|
||||
/* ---------- one exercise block (reps: weight×reps · time: a held duration · cardio: duration+speed) ---------- */
|
||||
function ExerciseBlock({ entryIdx, compact, onToggle, onField, onAddSet, onRemoveSet, onAddWarmup, onRemoveSetAt, onStartTimed, onPairPrev, onPairNext, onSetRowRef, onProgressionSettings, onSwap, onMoveUp, onMoveDown, canMoveUp, canMoveDown, onRemoveExercise, busy }) {
|
||||
// `compact` shrinks the block for a superset member; `dense` (compact view) goes further and
|
||||
// drops everything that is not a set you are logging — media, tag chips, the note lines, the
|
||||
// "last time" recap and the progression line — leaving the name, the ⋯ menu and the sets.
|
||||
// Nothing dropped is lost: it is all still on the ⋯ menu, or one ⋮ switch back to list/cards.
|
||||
function ExerciseBlock({ entryIdx, compact, dense, onToggle, onField, onAddSet, onRemoveSet, onAddWarmup, onRemoveSetAt, onStartTimed, onPairPrev, onPairNext, onSetRowRef, onProgressionSettings, onSwap, onMoveUp, onMoveDown, canMoveUp, canMoveDown, onRemoveExercise, busy }) {
|
||||
const S = useStore(s => s.S)
|
||||
const update = useStore(s => s.update)
|
||||
const working = useUI(s => s.work)
|
||||
@@ -242,19 +246,22 @@ function ExerciseBlock({ entryIdx, compact, onToggle, onField, onAddSet, onRemov
|
||||
</div>
|
||||
)
|
||||
return <>
|
||||
<Media ex={ex} key={entry.id} compact={compact} minimizable />
|
||||
{!dense && <Media ex={ex} key={entry.id} compact={compact} minimizable />}
|
||||
<div className="row between" style={{ marginBottom: 6 }}>
|
||||
<div style={{ fontSize: compact ? 17 : 20, fontWeight: 600, letterSpacing: '-.02em', textTransform: 'capitalize', lineHeight: 1.2 }}>{exerciseNameFor(ex)}</div>
|
||||
<div style={{ fontSize: (compact || dense) ? 17 : 20, fontWeight: 600, letterSpacing: '-.02em', textTransform: 'capitalize', lineHeight: 1.2 }}>{exerciseNameFor(ex)}</div>
|
||||
<div className="row" style={{ gap: 2, flex: 'none' }}>
|
||||
{entry.note && <button className="iconbtn" aria-label={t('Note')} title={t('Note')} style={{ color: 'var(--acc)' }}
|
||||
onClick={() => exerciseNoteSheet(entryIdx)}><Icon name="pencil" /></button>}
|
||||
<button className="iconbtn" aria-label={t('More')} title={t('More')} onClick={openMore}><Icon name="more" /></button>
|
||||
</div>
|
||||
</div>
|
||||
{wc.pairButtons && !compact && (onPairPrev || onPairNext) && <div className="row" style={{ gap: 6, flexWrap: 'wrap', marginBottom: 8 }}>
|
||||
{wc.pairButtons && !compact && !dense && (onPairPrev || onPairNext) && <div className="row" style={{ gap: 6, flexWrap: 'wrap', marginBottom: 8 }}>
|
||||
{onPairPrev && <Button size="xs" variant="tinted" icon="link" title={t('Make superset with previous')} onClick={onPairPrev}>{t('Make superset with previous')}</Button>}
|
||||
{onPairNext && <Button size="xs" variant="tinted" icon="link" title={t('Make superset with next')} onClick={onPairNext}>{t('Make superset with next')}</Button>}
|
||||
</div>}
|
||||
{/* compact view drops everything from here to the sets card — it is all still on the ⋯ menu
|
||||
(note, details, history, bar weight, progression) or is display-only (tags, "last time"). */}
|
||||
{!dense && <>
|
||||
<div className="row" style={{ gap: 6, flexWrap: 'wrap', marginBottom: 8 }}>
|
||||
{cardio && <span className="tag acc"><Icon name="figureRun" />{t('Cardio')}</span>}
|
||||
{/* You log the total; this is the split, so the set in front of you is unambiguous
|
||||
@@ -288,6 +295,7 @@ function ExerciseBlock({ entryIdx, compact, onToggle, onField, onAddSet, onRemov
|
||||
<Icon name={plan.kind === 'up' ? 'arrowUp' : plan.kind === 'deload' ? 'arrowDown' : 'lightbulb'} />
|
||||
<span><strong>{t(guidance.policyLabel)}</strong> · {t(...guidance.why)}</span>
|
||||
</button>}
|
||||
</>}
|
||||
<div className="card" style={{ marginTop: 10, marginBottom: 0 }}>
|
||||
{/* the header carries the same eff3 sizing as the rows, or the labels drift off their columns */}
|
||||
<div className={'sethead' + (col3 ? ' eff3' : '')}><span className="n-sp" /><span className="w-sp">{col1.hd}</span>{col2 && <span className="r-sp">{col2.hd}</span>}{col3 && <span className="eff-sp">{col3.hd}</span>}{timed && <span className="ck-sp" />}<span className="ck-sp" /></div>
|
||||
@@ -386,12 +394,17 @@ function ActiveWorkout() {
|
||||
const unit = A.entries.length ? unitOf(units, cur) : []
|
||||
const unitIdx = units.findIndex(u => u === unit)
|
||||
const isSuperset = unit.length > 1
|
||||
// Cards show one unit at a time with Prev/Next + swipe; list stacks every unit so the
|
||||
// whole session is visible and scrollable (Settings → During a workout → Workout view).
|
||||
// Every set handler below is already entry-index parameterised, so list mode only changes
|
||||
// what is rendered — completion, rest, top-weight and auto-advance share one path.
|
||||
// Unknown/absent values read as cards, keeping every pre-existing profile as it was.
|
||||
const listMode = S.workoutView === 'list'
|
||||
// Cards show one unit at a time with Prev/Next + swipe; list and compact stack every unit so
|
||||
// the whole session is visible and scrollable (Settings → During a workout → Workout view,
|
||||
// seeded onto s.active and overridable for this session from the header ⋮). compact is list
|
||||
// with the per-exercise media, tag chips, note lines, "last time" and progression line
|
||||
// stripped — just names and set rows. Every set handler below is already entry-index
|
||||
// parameterised, so these only change what is rendered — completion, rest, top-weight and
|
||||
// auto-advance share one path. Unknown/absent values read as cards, keeping every
|
||||
// pre-existing profile (and a session started before this field) as it was.
|
||||
const workoutView = A.workoutView || S.workoutView
|
||||
const listMode = workoutView === 'list' || workoutView === 'compact'
|
||||
const dense = workoutView === 'compact'
|
||||
const wc = workoutControls(S)
|
||||
// Superset flow: center the actionable row when completing a set moves to the partner or
|
||||
// back to the first exercise of the next round. Entry-bound maps keep repeated exercise IDs
|
||||
@@ -536,6 +549,18 @@ function ActiveWorkout() {
|
||||
// "Set current" on its header instead of Prev/Next. The bottom Move/Swap/Remove actions
|
||||
// keep operating on it, and completing sets still advances it on its own.
|
||||
const focusUnit = firstIdx => update(s => { if (s.active) s.active.cur = firstIdx })
|
||||
// The header ⋮ re-lays-out the running session without touching the saved default
|
||||
// (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'),
|
||||
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') },
|
||||
],
|
||||
})
|
||||
const onSwipePointerDown = event => {
|
||||
if (swipe.current || (event.pointerType && event.pointerType !== 'touch' && event.pointerType !== 'pen')) return
|
||||
if (event.target.closest?.(SWIPE_IGNORED_TARGETS)) return
|
||||
@@ -751,7 +776,10 @@ function ActiveWorkout() {
|
||||
<div className="hdr">
|
||||
<button className="iconbtn" aria-label={t('Discard')} onClick={() => confirmSheet({ title: t('Discard workout?'), message: t('The sets you logged in this session will be lost.'), confirmText: t('Discard'), danger: true, onConfirm: () => { update(s => { s.active = null }); stopRest(); stopWork(); nav('/home') } })}><Icon name="xmark" /></button>
|
||||
<div style={{ textAlign: 'center' }}><div style={{ fontWeight: 600 }}>{A.name}</div><div className="sub">{A.backfill ? fmtDate(A.d, true) : <Elapsed start={A.start} />} · {t('{0} sets', done + '/' + total)}</div></div>
|
||||
<button className="iconbtn" style={{ color: 'var(--acc)' }} aria-label={t('Finish')} onClick={finishWorkout}><Icon name="check" /></button>
|
||||
<div className="row" style={{ gap: 4, flex: 'none' }}>
|
||||
<button className="iconbtn" aria-label={t('Workout view')} title={t('Workout view')} onClick={openViewMenu}><Icon name="more" /></button>
|
||||
<button className="iconbtn" style={{ color: 'var(--acc)' }} aria-label={t('Finish')} onClick={finishWorkout}><Icon name="check" /></button>
|
||||
</div>
|
||||
</div>
|
||||
<div className="wprog"><i style={{ width: (total ? done / total * 100 : 0) + '%' }} /></div>
|
||||
</div>
|
||||
@@ -779,13 +807,13 @@ function ActiveWorkout() {
|
||||
const entry = A.entries[idx]
|
||||
return <div key={idx} ref={el => bindExRef(entry, el)} className="ss-ex" data-exidx={idx}>
|
||||
{k > 0 && <div className="ss-amp">+</div>}
|
||||
<ExerciseBlock entryIdx={idx} compact onSetRowRef={(setIdx, el) => bindSetRef(entry, setIdx, el)}
|
||||
<ExerciseBlock entryIdx={idx} compact dense={dense} onSetRowRef={(setIdx, el) => bindSetRef(entry, setIdx, el)}
|
||||
{...blockProps(idx)} />
|
||||
</div>
|
||||
})}
|
||||
</div>
|
||||
) : (
|
||||
<ExerciseBlock entryIdx={u[0]}
|
||||
<ExerciseBlock entryIdx={u[0]} dense={dense}
|
||||
onPairPrev={u[0] > 0 ? () => pairAt(u[0] - 1, u[0]) : null}
|
||||
onPairNext={u[0] < A.entries.length - 1 ? () => pairAt(u[0], u[0] + 1) : null}
|
||||
{...blockProps(u[0])} />
|
||||
|
||||
@@ -1075,6 +1075,107 @@ describe('workout list view', () => {
|
||||
// Only the current exercise's sets are on screen.
|
||||
expect(container.querySelectorAll('[role="checkbox"]').length).toBe(1)
|
||||
})
|
||||
|
||||
it('reads the layout from s.active first, then the global default', async () => {
|
||||
// Global says list, the session was started as cards — the session wins.
|
||||
await mount([exercise('plain-bench', [false])], 0, {
|
||||
workoutView: 'list', active: { workoutView: 'cards' },
|
||||
})
|
||||
expect(container.querySelector('[data-testid="workout-swipe-surface"]')).toBeTruthy()
|
||||
expect(container.querySelector('[data-testid="workout-list"]')).toBeNull()
|
||||
})
|
||||
})
|
||||
|
||||
describe('workout compact view', () => {
|
||||
const units = () => [...container.querySelectorAll('.wl-unit')]
|
||||
const withExtras = done => exercise('plain-bench', done, {
|
||||
plan: {
|
||||
policy: 'linear', kind: 'up', weight: 62.5,
|
||||
why: ['Every rep last time — {0} {1} more.', 2.5, 'kg'],
|
||||
},
|
||||
})
|
||||
|
||||
it('stacks every exercise like list mode does', async () => {
|
||||
await mount([withExtras([false, false]), exercise('plain-row', [false])], 0, { workoutView: 'compact' })
|
||||
|
||||
expect(container.querySelector('[data-testid="workout-list"]')).toBeTruthy()
|
||||
expect(container.querySelector('[data-testid="workout-swipe-surface"]')).toBeNull()
|
||||
expect(units().length).toBe(2)
|
||||
expect(container.querySelectorAll('[role="checkbox"]').length).toBe(3)
|
||||
// The unit header and its "Set current" chip are part of list mode, kept in compact.
|
||||
expect(units()[0].textContent).toContain('Current')
|
||||
})
|
||||
|
||||
it('strips the progression line, tags and last-time recap that list mode shows', async () => {
|
||||
const state = {
|
||||
workoutView: 'compact',
|
||||
exWeights: { 'plain-bench': { w: 80 } },
|
||||
workouts: [{ d: '2026-08-27', entries: [{ id: 'plain-bench', target: { reps: 5, weight: 60 }, sets: [{ w: 60, r: 5, done: true }] }] }],
|
||||
}
|
||||
await mount([withExtras([false])], 0, state)
|
||||
|
||||
expect(container.querySelector('.progline')).toBeNull()
|
||||
expect(container.textContent).not.toContain('Best:')
|
||||
expect(container.textContent).not.toContain('Last time')
|
||||
// The sets card and the ⋯ menu button survive — nothing is truly unreachable.
|
||||
expect(container.querySelector('.setrow')).toBeTruthy()
|
||||
expect(container.querySelector('button[aria-label="More"]')).toBeTruthy()
|
||||
})
|
||||
|
||||
it('keeps those same elements in list mode (the strip is compact-only)', async () => {
|
||||
const state = {
|
||||
workoutView: 'list',
|
||||
exWeights: { 'plain-bench': { w: 80 } },
|
||||
workouts: [{ d: '2026-08-27', entries: [{ id: 'plain-bench', target: { reps: 5, weight: 60 }, sets: [{ w: 60, r: 5, done: true }] }] }],
|
||||
}
|
||||
await mount([withExtras([false])], 0, state)
|
||||
|
||||
expect(container.querySelector('.progline')).toBeTruthy()
|
||||
expect(container.textContent).toContain('Best:')
|
||||
expect(container.textContent).toContain('Last time')
|
||||
})
|
||||
|
||||
it('completing a set still starts the rest, like list and cards', async () => {
|
||||
await mount([
|
||||
exercise('plain-bench', [false], { asked: true }),
|
||||
exercise('plain-row', [false], { asked: true }),
|
||||
], 0, { workoutView: 'compact' })
|
||||
|
||||
await toggleSet(0)
|
||||
|
||||
expect(mocks.S.active.entries[0].sets[0].done).toBe(true)
|
||||
expect(mocks.startRest).toHaveBeenCalledWith(90, expect.any(Number))
|
||||
})
|
||||
})
|
||||
|
||||
describe('workout view header menu', () => {
|
||||
const openMenu = async () => {
|
||||
const btn = container.querySelector('button[aria-label="Workout view"]')
|
||||
expect(btn).toBeTruthy()
|
||||
await act(async () => { btn.dispatchEvent(new dom.Event('click', { bubbles: true })) })
|
||||
return mocks.menuSheet.mock.calls.at(-1)[0]
|
||||
}
|
||||
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' } })
|
||||
|
||||
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)
|
||||
})
|
||||
|
||||
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' } })
|
||||
|
||||
const menu = await openMenu()
|
||||
await act(async () => { item(menu, 'Compact').onClick() })
|
||||
|
||||
expect(mocks.S.active.workoutView).toBe('compact')
|
||||
expect(mocks.S.workoutView).toBe('cards')
|
||||
})
|
||||
})
|
||||
|
||||
describe('workout controls: the more menu and the set menu', () => {
|
||||
|
||||
Reference in new issue
Block a user