From 64563c257b1636d658dd7e08af2496422da9e65e Mon Sep 17 00:00:00 2001 From: Henry Date: Sun, 6 Sep 2026 01:16:28 +0100 Subject: [PATCH] =?UTF-8?q?Workout=20view:=20add=20a=20"compact"=20layout?= =?UTF-8?q?=20and=20a=20per-session=20=E2=8B=AE=20switcher?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 Claude-Session: https://claude.ai/code/session_016QqZBhX7PVNsRqLhkTt9y3 --- docs/LIST_VIEW.md | 36 +++++++ frontend/src/lib/pt-br-locale.test.js | 4 +- frontend/src/locales/de.js | 1 + frontend/src/locales/es.js | 1 + frontend/src/locales/fr.js | 1 + frontend/src/locales/hi.js | 1 + frontend/src/locales/hu.js | 1 + frontend/src/locales/it.js | 1 + frontend/src/locales/ko.js | 1 + frontend/src/locales/pl.js | 1 + frontend/src/locales/pt.js | 1 + frontend/src/locales/ru.js | 1 + frontend/src/locales/th.js | 1 + frontend/src/locales/tr.js | 1 + frontend/src/locales/zh.js | 1 + frontend/src/sheets.jsx | 5 + frontend/src/sheets.workoutview.test.jsx | 65 +++++++++++ frontend/src/store/useStore.js | 9 +- frontend/src/views/Settings.jsx | 10 +- .../src/views/Settings.workoutview.test.jsx | 8 +- frontend/src/views/Workout.jsx | 54 +++++++--- frontend/src/views/Workout.test.jsx | 101 ++++++++++++++++++ 22 files changed, 282 insertions(+), 23 deletions(-) create mode 100644 docs/LIST_VIEW.md create mode 100644 frontend/src/sheets.workoutview.test.jsx diff --git a/docs/LIST_VIEW.md b/docs/LIST_VIEW.md new file mode 100644 index 0000000..339867c --- /dev/null +++ b/docs/LIST_VIEW.md @@ -0,0 +1,36 @@ +# Workout view — cards / list / compact + +The active workout screen (`frontend/src/views/Workout.jsx`) has three layouts, chosen by +`S.workoutView` (`'cards' | 'list' | 'compact'`, default `'cards'`). It is purely +presentational — the same `s.active` session, entries and finish path in every layout, and +every set handler is already entry-index parameterised, so the layouts only change what is +rendered. + +| Value | What you see | +|---|---| +| `cards` | One unit at a time, `Prev` / `Next` + swipe. The original flow. | +| `list` | Every unit stacked and scrollable. Each unit has a header (`Exercise n / m`) with a **Set current** chip; the footer's Move / Swap / Remove act on the current unit; completion still auto-advances the marker, starts rest and can open the top-weight sheet. | +| `compact` | `list`, with each `ExerciseBlock` rendered `dense`: no media, no tag chips (Cardio / per-side / target / equipment / **Best:**), no note lines, no "Last time …" recap, no bar-and-plates chip, no progression-guidance line. Just the name, the ⋯ menu and the set rows. Everything stripped is still on the ⋯ menu (note, details, history, bar weight, progression settings) or is display-only. | + +Unknown / absent values read as `cards`, so a profile written before the setting existed is +unchanged. + +## Where it is set + +- **Saved default:** Settings → During a workout → **Workout view** (a 3-way `Segmented`). +- **Per session:** the workout header's **⋮** button opens a `menuSheet` with the three + layouts; picking one writes `s.active.workoutView`. + +`beginWorkout` / `beginBackfill` (`frontend/src/sheets.jsx`) snapshot `S.workoutView` onto +`s.active.workoutView` when the session is created, and the render prefers +`A.workoutView || S.workoutView`. So the ⋮ menu re-lays-out the running session only, and +changing the saved default never disturbs a workout already in progress. + +## Tests + +Component-level, no new `lib/` helper: + +- `frontend/src/views/Workout.test.jsx` — `workout list view`, `workout compact view`, + `workout view header menu` describe blocks. +- `frontend/src/views/Settings.workoutview.test.jsx` — the 3-way Segmented. +- `frontend/src/sheets.workoutview.test.jsx` — `beginWorkout` / backfill snapshot behaviour. diff --git a/frontend/src/lib/pt-br-locale.test.js b/frontend/src/lib/pt-br-locale.test.js index 1e6dc9b..fa35e2e 100644 --- a/frontend/src/lib/pt-br-locale.test.js +++ b/frontend/src/lib/pt-br-locale.test.js @@ -28,10 +28,10 @@ describe('Brazilian Portuguese locale', () => { const fingerprint = createHash('sha256').update(JSON.stringify(inherited)).digest('hex') expect(Object.keys(PT_BR_OVERRIDES)).toHaveLength(626) - expect(inherited).toHaveLength(613) + expect(inherited).toHaveLength(614) // If this fails, review the changed keys and wording before accepting a new hash. From // frontend/: node scripts/pt-br-inheritance-fingerprint.mjs --list - expect(fingerprint, 'pt-PT inheritance changed; review the inherited pt-BR wording').toBe('81d277306b3029090b7a2ba6cc19108ca207ea65d738487155123260b6e9525d') + expect(fingerprint, 'pt-PT inheritance changed; review the inherited pt-BR wording').toBe('b7e4e1f39100061735da0725188e593ce56ac080696eb32a71a38b03223a2fd6') }) test('does not leak European Portuguese UI terms', () => { diff --git a/frontend/src/locales/de.js b/frontend/src/locales/de.js index 5b0e2ff..63c1f06 100644 --- a/frontend/src/locales/de.js +++ b/frontend/src/locales/de.js @@ -441,6 +441,7 @@ export default { 'Workout view': 'Trainingsansicht', 'Cards': 'Karten', 'List': 'Liste', + 'Compact': 'Kompakt', 'Current': 'Aktuell', 'Set current': 'Als aktuell markieren', 'Move, swap and remove below act on the exercise marked {0}.': 'Verschieben, Tauschen und Entfernen unten wirken auf die als {0} markierte Übung.', diff --git a/frontend/src/locales/es.js b/frontend/src/locales/es.js index b933ef8..197874c 100644 --- a/frontend/src/locales/es.js +++ b/frontend/src/locales/es.js @@ -423,6 +423,7 @@ export default { 'Workout view': 'Vista del entrenamiento', 'Cards': 'Tarjetas', 'List': 'Lista', + 'Compact': 'Compacta', 'Current': 'Actual', 'Set current': 'Marcar actual', 'Move, swap and remove below act on the exercise marked {0}.': 'Mover, cambiar y eliminar actúan sobre el ejercicio marcado como {0}.', diff --git a/frontend/src/locales/fr.js b/frontend/src/locales/fr.js index 4437662..ef60edb 100644 --- a/frontend/src/locales/fr.js +++ b/frontend/src/locales/fr.js @@ -423,6 +423,7 @@ export default { 'Workout view': 'Vue de l’entraînement', 'Cards': 'Cartes', 'List': 'Liste', + 'Compact': 'Compacte', 'Current': 'En cours', 'Set current': 'Marquer comme en cours', 'Move, swap and remove below act on the exercise marked {0}.': 'Déplacer, échanger et supprimer ci-dessous s’appliquent à l’exercice marqué {0}.', diff --git a/frontend/src/locales/hi.js b/frontend/src/locales/hi.js index 7b5bb0d..b1c11ae 100644 --- a/frontend/src/locales/hi.js +++ b/frontend/src/locales/hi.js @@ -423,6 +423,7 @@ export default { 'Workout view': 'वर्कआउट दृश्य', 'Cards': 'कार्ड', 'List': 'सूची', + 'Compact': 'संक्षिप्त', 'Current': 'वर्तमान', 'Set current': 'वर्तमान के रूप में चिह्नित करें', 'Move, swap and remove below act on the exercise marked {0}.': 'नीचे दिए गए मूव, स्वैप और रिमूव {0} के रूप में चिह्नित व्यायाम पर लागू होते हैं।', diff --git a/frontend/src/locales/hu.js b/frontend/src/locales/hu.js index b8a3d46..047d8bf 100644 --- a/frontend/src/locales/hu.js +++ b/frontend/src/locales/hu.js @@ -433,6 +433,7 @@ export default { 'Workout view': 'Edzésnézet', 'Cards': 'Kártyák', 'List': 'Lista', + 'Compact': 'Tömör', 'Current': 'Aktuális', 'Set current': 'Megjelölés aktuálisként', 'Move, swap and remove below act on the exercise marked {0}.': 'Az alábbi áthelyezés, csere és törlés a {0} jelölésű gyakorlatra vonatkozik.', diff --git a/frontend/src/locales/it.js b/frontend/src/locales/it.js index bbd9057..6481b25 100644 --- a/frontend/src/locales/it.js +++ b/frontend/src/locales/it.js @@ -423,6 +423,7 @@ export default { 'Workout view': 'Vista allenamento', 'Cards': 'Schede', 'List': 'Elenco', + 'Compact': 'Compatta', 'Current': 'Corrente', 'Set current': 'Imposta come corrente', 'Move, swap and remove below act on the exercise marked {0}.': 'Spostamento, scambio e rimozione qui sotto agiscono sull’esercizio contrassegnato come {0}.', diff --git a/frontend/src/locales/ko.js b/frontend/src/locales/ko.js index aba5bf2..4637db1 100644 --- a/frontend/src/locales/ko.js +++ b/frontend/src/locales/ko.js @@ -423,6 +423,7 @@ export default { 'Workout view': '운동 보기', 'Cards': '카드', 'List': '목록', + 'Compact': '간략', 'Current': '현재', 'Set current': '현재 운동으로 설정', 'Move, swap and remove below act on the exercise marked {0}.': '아래의 이동, 교체, 삭제는 {0} 표시된 운동에 적용됩니다.', diff --git a/frontend/src/locales/pl.js b/frontend/src/locales/pl.js index 544b6c4..45a0875 100644 --- a/frontend/src/locales/pl.js +++ b/frontend/src/locales/pl.js @@ -423,6 +423,7 @@ export default { 'Workout view': 'Widok treningu', 'Cards': 'Karty', 'List': 'Lista', + 'Compact': 'Kompaktowy', 'Current': 'Bieżące', 'Set current': 'Ustaw jako bieżące', 'Move, swap and remove below act on the exercise marked {0}.': 'Przenoszenie, zamiana i usuwanie poniżej dotyczą ćwiczenia oznaczonego {0}.', diff --git a/frontend/src/locales/pt.js b/frontend/src/locales/pt.js index f06f986..791ce69 100644 --- a/frontend/src/locales/pt.js +++ b/frontend/src/locales/pt.js @@ -423,6 +423,7 @@ export default { 'Workout view': 'Vista do treino', 'Cards': 'Cartões', 'List': 'Lista', + 'Compact': 'Compacta', 'Current': 'Atual', 'Set current': 'Marcar como atual', 'Move, swap and remove below act on the exercise marked {0}.': 'Mover, trocar e remover abaixo atuam sobre o exercício marcado como {0}.', diff --git a/frontend/src/locales/ru.js b/frontend/src/locales/ru.js index adcc629..5e083de 100644 --- a/frontend/src/locales/ru.js +++ b/frontend/src/locales/ru.js @@ -423,6 +423,7 @@ export default { 'Workout view': 'Вид тренировки', 'Cards': 'Карточки', 'List': 'Список', + 'Compact': 'Компактный', 'Current': 'Текущее', 'Set current': 'Сделать текущим', 'Move, swap and remove below act on the exercise marked {0}.': 'Кнопки перемещения, замены и удаления ниже действуют на упражнение с пометкой {0}.', diff --git a/frontend/src/locales/th.js b/frontend/src/locales/th.js index 229a024..6f5399a 100644 --- a/frontend/src/locales/th.js +++ b/frontend/src/locales/th.js @@ -433,6 +433,7 @@ export default { 'Workout view': 'มุมมองการฝึก', 'Cards': 'การ์ด', 'List': 'รายการ', + 'Compact': 'แบบย่อ', 'Current': 'ปัจจุบัน', 'Set current': 'ตั้งเป็นปัจจุบัน', 'Move, swap and remove below act on the exercise marked {0}.': 'การย้าย สลับ และลบด้านล่างจะมีผลกับท่าที่ทำเครื่องหมาย {0} ไว้', diff --git a/frontend/src/locales/tr.js b/frontend/src/locales/tr.js index d4d554b..4e1a40e 100644 --- a/frontend/src/locales/tr.js +++ b/frontend/src/locales/tr.js @@ -423,6 +423,7 @@ export default { 'Workout view': 'Antrenman görünümü', 'Cards': 'Kartlar', 'List': 'Liste', + 'Compact': 'Kompakt', 'Current': 'Aktif', 'Set current': 'Aktif olarak işaretle', 'Move, swap and remove below act on the exercise marked {0}.': 'Aşağıdaki taşıma, değiştirme ve kaldırma işlemleri {0} olarak işaretli egzersiz için geçerlidir.', diff --git a/frontend/src/locales/zh.js b/frontend/src/locales/zh.js index 05108b7..6b932a6 100644 --- a/frontend/src/locales/zh.js +++ b/frontend/src/locales/zh.js @@ -423,6 +423,7 @@ export default { 'Workout view': '训练视图', 'Cards': '卡片', 'List': '列表', + 'Compact': '紧凑', 'Current': '当前', 'Set current': '设为当前', 'Move, swap and remove below act on the exercise marked {0}.': '下方的移动、替换和删除将作用于标记为{0}的动作。', diff --git a/frontend/src/sheets.jsx b/frontend/src/sheets.jsx index 29a38ff..f239a0d 100644 --- a/frontend/src/sheets.jsx +++ b/frontend/src/sheets.jsx @@ -1668,6 +1668,9 @@ export function beginWorkout(routineId, bw) { s.active = { id: uid(), d: todayISO(), start: Date.now(), routineId, name: r ? r.name : t('Freestyle'), bw: bw || null, cur: 0, entries, + // Snapshot the layout at start so the header ⋮ can change it for this session only — + // changing the saved default (Settings → Workout view) mid-session leaves it alone. + workoutView: st.workoutView || 'cards', ...(excluded ? { excludeFromProgression: true } : {}) } }) @@ -1742,6 +1745,8 @@ function beginBackfill({ iso, time, durationMin, routineId, replaceId }) { id: uid(), d: iso, start: backfillStart(iso, time), routineId, name: r ? r.name : t('Freestyle'), bw: null, cur: 0, entries, backfill: { durationMin, replaceId: replaceId || null }, + // Same layout snapshot as a live session (see beginWorkout). + workoutView: st.workoutView || 'cards', ...(excluded ? { excludeFromProgression: true } : {}) } }) diff --git a/frontend/src/sheets.workoutview.test.jsx b/frontend/src/sheets.workoutview.test.jsx new file mode 100644 index 0000000..ceec228 --- /dev/null +++ b/frontend/src/sheets.workoutview.test.jsx @@ -0,0 +1,65 @@ +// @vitest-environment happy-dom +import React, { act } from 'react' +import { afterEach, beforeEach, describe, expect, it } from 'vitest' +import { createRoot } from 'react-dom/client' +import { useStore } from './store/useStore.js' +import { useUI } from './store/useUI.js' +import { beginWorkout, logPastWorkoutSheet } from './sheets.jsx' +import { todayISO } from './lib/format.js' + +// beginWorkout / beginBackfill snapshot S.workoutView onto s.active so the header ⋮ can +// re-lay-out the running session without touching the saved default. + +const mounted = [] +function type(el, value) { + Object.getOwnPropertyDescriptor(el.constructor.prototype, 'value').set.call(el, value) + el.dispatchEvent(new Event('input', { bubbles: true })) +} +function mountTopSheet() { + const sheet = useUI.getState().sheets.at(-1) + const host = document.createElement('div') + document.body.appendChild(host) + const root = createRoot(host) + mounted.push(root) + act(() => root.render(sheet.render(() => useUI.getState().closeSheet(sheet.id)))) + return host +} +const button = (host, text) => [...host.querySelectorAll('button')].find(b => b.textContent.trim() === text) + +describe('workout view is snapshot onto the active session', () => { + beforeEach(() => { + globalThis.IS_REACT_ACT_ENVIRONMENT = true + useUI.setState({ sheets: [], toasts: [] }) + useStore.setState(s => ({ S: { ...s.S, active: null, routines: [], workouts: [], workoutView: 'cards' } })) + document.body.innerHTML = '' + }) + afterEach(() => { act(() => { mounted.splice(0).forEach(root => root.unmount()) }) }) + + it('beginWorkout copies the current default onto s.active', () => { + useStore.setState(s => ({ S: { ...s.S, workoutView: 'compact' } })) + act(() => beginWorkout(null, null)) + expect(useStore.getState().S.active.workoutView).toBe('compact') + }) + + it('beginWorkout falls back to cards when the default is unset', () => { + useStore.setState(s => { const S = { ...s.S }; delete S.workoutView; return { S } }) + act(() => beginWorkout(null, null)) + expect(useStore.getState().S.active.workoutView).toBe('cards') + }) + + it('later changes to the default leave the running session alone', () => { + act(() => beginWorkout(null, null)) + expect(useStore.getState().S.active.workoutView).toBe('cards') + useStore.setState(s => ({ S: { ...s.S, workoutView: 'list' } })) + expect(useStore.getState().S.active.workoutView).toBe('cards') + }) + + it('a backfilled session snapshots it too', () => { + useStore.setState(s => ({ S: { ...s.S, workoutView: 'list' } })) + logPastWorkoutSheet() + const host = mountTopSheet() + act(() => { type(host.querySelector('input[type=date]'), '2020-01-02') }) + act(() => { button(host, 'Continue').click() }) + expect(useStore.getState().S.active.workoutView).toBe('list') + }) +}) diff --git a/frontend/src/store/useStore.js b/frontend/src/store/useStore.js index 33dd4a7..2a0cdce 100644 --- a/frontend/src/store/useStore.js +++ b/frontend/src/store/useStore.js @@ -16,9 +16,12 @@ export const DEF = { theme: 'dark', accent: 'lime', body: 'male', targetW: null, bodyweight: [], routines: [], week: {}, dayPlan: {}, exWeights: {}, workouts: [], active: null, customEx: [], gifSize: 'full', - // How the active workout is laid out — 'cards' (one exercise at a time with Prev/Next) - // or 'list' (every exercise stacked and scrollable). Purely presentational: profiles - // written before this setting existed overlay onto DEF and keep the 'cards' behaviour. + // How the active workout is laid out — 'cards' (one exercise at a time with Prev/Next), + // 'list' (every exercise stacked and scrollable) or 'compact' (that stack stripped to just + // names and set rows — no media, tags, notes, last-time or progression line). Purely + // presentational: profiles written before this setting existed overlay onto DEF and keep the + // 'cards' behaviour. beginWorkout copies the value onto s.active, so the header ⋮ menu can + // override it for the running session without touching this saved default. workoutView: 'cards', // Which controls the workout screen shows besides the sets themselves. The default is the // lean layout: one "more" button per exercise and a menu on each set number. Every switch diff --git a/frontend/src/views/Settings.jsx b/frontend/src/views/Settings.jsx index f9e0bad..854c7cc 100644 --- a/frontend/src/views/Settings.jsx +++ b/frontend/src/views/Settings.jsx @@ -223,12 +223,14 @@ export default function Settings() { {/* ---------- during a workout ---------- */}
- {/* 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. */} update(s => { s.workoutView = v })} /> {/* The lean workout screen keeps the sets and one "more" button per exercise; each switch diff --git a/frontend/src/views/Settings.workoutview.test.jsx b/frontend/src/views/Settings.workoutview.test.jsx index 2bd990b..a58b2d5 100644 --- a/frontend/src/views/Settings.workoutview.test.jsx +++ b/frontend/src/views/Settings.workoutview.test.jsx @@ -67,15 +67,20 @@ const mount = () => act(() => root.render()) 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') }) }) diff --git a/frontend/src/views/Workout.jsx b/frontend/src/views/Workout.jsx index a9f8a09..dcae25a 100644 --- a/frontend/src/views/Workout.jsx +++ b/frontend/src/views/Workout.jsx @@ -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 ) return <> - + {!dense && }
-
{exerciseNameFor(ex)}
+
{exerciseNameFor(ex)}
{entry.note && }
- {wc.pairButtons && !compact && (onPairPrev || onPairNext) &&
+ {wc.pairButtons && !compact && !dense && (onPairPrev || onPairNext) &&
{onPairPrev && } {onPairNext && }
} + {/* 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 && <>
{cardio && {t('Cardio')}} {/* 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 {t(guidance.policyLabel)} · {t(...guidance.why)} } + }
{/* the header carries the same eff3 sizing as the rows, or the labels drift off their columns */}
{col1.hd}{col2 && {col2.hd}}{col3 && {col3.hd}}{timed && }
@@ -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() {
{A.name}
{A.backfill ? fmtDate(A.d, true) : } · {t('{0} sets', done + '/' + total)}
- +
+ + +
@@ -779,13 +807,13 @@ function ActiveWorkout() { const entry = A.entries[idx] return
bindExRef(entry, el)} className="ss-ex" data-exidx={idx}> {k > 0 &&
+
} - bindSetRef(entry, setIdx, el)} + bindSetRef(entry, setIdx, el)} {...blockProps(idx)} />
})}
) : ( - 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])} /> diff --git a/frontend/src/views/Workout.test.jsx b/frontend/src/views/Workout.test.jsx index 140d4ca..fbd3bc6 100644 --- a/frontend/src/views/Workout.test.jsx +++ b/frontend/src/views/Workout.test.jsx @@ -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', () => {