feat(workout): add configurable list view for active workouts
This commit is contained in:
1 parent
d6f0db9b4b
commit
e278051fae
20 files changed
+332
-11
No files matched your search
@@ -1010,6 +1010,18 @@ h4.sec{
|
||||
.ss-ex{position:relative}
|
||||
.ss-amp{text-align:center;font-size:15px;font-weight:600;color:var(--acc);margin:14px 0 8px}
|
||||
|
||||
/* --- workout list view: every unit stacked, the current one outlined --- */
|
||||
.workout-list{display:grid;gap:14px}
|
||||
.wl-unit{
|
||||
border-radius:var(--r-lg);padding:14px 14px 4px;
|
||||
background:var(--surface-2);
|
||||
}
|
||||
.wl-unit.cur{box-shadow:inset 0 0 0 1.5px var(--acc-line)}
|
||||
.wl-hd{display:flex;align-items:center;justify-content:space-between;gap:8px;margin-bottom:10px}
|
||||
@media (max-width:400px){
|
||||
.wl-unit{padding:10px 8px 2px}
|
||||
}
|
||||
|
||||
/* --- home: today's session row --- */
|
||||
.today-row{
|
||||
display:flex;align-items:center;justify-content:space-between;gap:10px;
|
||||
|
||||
@@ -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(586)
|
||||
expect(inherited).toHaveLength(553)
|
||||
expect(inherited).toHaveLength(559)
|
||||
// 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('4a550b06e44cabd2b69834c15607220ca547854f2b0934843cadaa60a7f61a27')
|
||||
expect(fingerprint, 'pt-PT inheritance changed; review the inherited pt-BR wording').toBe('ae49ea702bb600947e67170a1ef61c0518a326724c83b8484ce7199f1393700b')
|
||||
})
|
||||
|
||||
test('does not leak European Portuguese UI terms', () => {
|
||||
|
||||
@@ -412,6 +412,12 @@ export default {
|
||||
'Minimize': 'Verkleinern',
|
||||
'Expand': 'Vergrössern',
|
||||
'Exercise animations': 'Übungs-Animationen',
|
||||
'Workout view': 'Trainingsansicht',
|
||||
'Cards': 'Karten',
|
||||
'List': 'Liste',
|
||||
'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.',
|
||||
'Full': 'Gross',
|
||||
'Small': 'Klein',
|
||||
'Hidden': 'Versteckt',
|
||||
|
||||
@@ -394,6 +394,12 @@ export default {
|
||||
'Minimize': 'Minimizar',
|
||||
'Expand': 'Ampliar',
|
||||
'Exercise animations': 'Animaciones de los ejercicios',
|
||||
'Workout view': 'Vista del entrenamiento',
|
||||
'Cards': 'Tarjetas',
|
||||
'List': 'Lista',
|
||||
'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}.',
|
||||
'Full': 'Completa',
|
||||
'Small': 'Pequeña',
|
||||
'Hidden': 'Oculta',
|
||||
|
||||
@@ -394,6 +394,12 @@ export default {
|
||||
'Minimize': 'Réduire',
|
||||
'Expand': 'Agrandir',
|
||||
'Exercise animations': 'Animations des exercices',
|
||||
'Workout view': 'Vue de l’entraînement',
|
||||
'Cards': 'Cartes',
|
||||
'List': 'Liste',
|
||||
'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}.',
|
||||
'Full': 'Grande',
|
||||
'Small': 'Petite',
|
||||
'Hidden': 'Masquée',
|
||||
|
||||
@@ -394,6 +394,12 @@ export default {
|
||||
'Minimize': 'छोटा करें',
|
||||
'Expand': 'बड़ा करें',
|
||||
'Exercise animations': 'व्यायाम एनिमेशन',
|
||||
'Workout view': 'वर्कआउट दृश्य',
|
||||
'Cards': 'कार्ड',
|
||||
'List': 'सूची',
|
||||
'Current': 'वर्तमान',
|
||||
'Set current': 'वर्तमान के रूप में चिह्नित करें',
|
||||
'Move, swap and remove below act on the exercise marked {0}.': 'नीचे दिए गए मूव, स्वैप और रिमूव {0} के रूप में चिह्नित व्यायाम पर लागू होते हैं।',
|
||||
'Full': 'पूर्ण',
|
||||
'Small': 'छोटा',
|
||||
'Hidden': 'छिपा',
|
||||
|
||||
@@ -404,6 +404,12 @@ export default {
|
||||
'Minimize': 'Kicsinyítés',
|
||||
'Expand': 'Kibontás',
|
||||
'Exercise animations': 'Gyakorlat-animációk',
|
||||
'Workout view': 'Edzésnézet',
|
||||
'Cards': 'Kártyák',
|
||||
'List': 'Lista',
|
||||
'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.',
|
||||
'Full': 'Teljes',
|
||||
'Small': 'Kicsi',
|
||||
'Hidden': 'Rejtett',
|
||||
|
||||
@@ -394,6 +394,12 @@ export default {
|
||||
'Minimize': 'Riduci',
|
||||
'Expand': 'Ingrandisci',
|
||||
'Exercise animations': 'Animazioni degli esercizi',
|
||||
'Workout view': 'Vista allenamento',
|
||||
'Cards': 'Schede',
|
||||
'List': 'Elenco',
|
||||
'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}.',
|
||||
'Full': 'Grande',
|
||||
'Small': 'Piccola',
|
||||
'Hidden': 'Nascosta',
|
||||
|
||||
@@ -394,6 +394,12 @@ export default {
|
||||
'Minimize': '축소',
|
||||
'Expand': '확대',
|
||||
'Exercise animations': '운동 애니메이션',
|
||||
'Workout view': '운동 보기',
|
||||
'Cards': '카드',
|
||||
'List': '목록',
|
||||
'Current': '현재',
|
||||
'Set current': '현재 운동으로 설정',
|
||||
'Move, swap and remove below act on the exercise marked {0}.': '아래의 이동, 교체, 삭제는 {0} 표시된 운동에 적용됩니다.',
|
||||
'Full': '전체',
|
||||
'Small': '작게',
|
||||
'Hidden': '숨김',
|
||||
|
||||
@@ -394,6 +394,12 @@ export default {
|
||||
'Minimize': 'Zmniejsz',
|
||||
'Expand': 'Powiększ',
|
||||
'Exercise animations': 'Animacje ćwiczeń',
|
||||
'Workout view': 'Widok treningu',
|
||||
'Cards': 'Karty',
|
||||
'List': 'Lista',
|
||||
'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}.',
|
||||
'Full': 'Pełna',
|
||||
'Small': 'Mała',
|
||||
'Hidden': 'Ukryta',
|
||||
|
||||
@@ -394,6 +394,12 @@ export default {
|
||||
'Minimize': 'Minimizar',
|
||||
'Expand': 'Ampliar',
|
||||
'Exercise animations': 'Animações dos exercícios',
|
||||
'Workout view': 'Vista do treino',
|
||||
'Cards': 'Cartões',
|
||||
'List': 'Lista',
|
||||
'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}.',
|
||||
'Full': 'Grande',
|
||||
'Small': 'Pequena',
|
||||
'Hidden': 'Oculta',
|
||||
|
||||
@@ -394,6 +394,12 @@ export default {
|
||||
'Minimize': 'Свернуть',
|
||||
'Expand': 'Развернуть',
|
||||
'Exercise animations': 'Анимации упражнений',
|
||||
'Workout view': 'Вид тренировки',
|
||||
'Cards': 'Карточки',
|
||||
'List': 'Список',
|
||||
'Current': 'Текущее',
|
||||
'Set current': 'Сделать текущим',
|
||||
'Move, swap and remove below act on the exercise marked {0}.': 'Кнопки перемещения, замены и удаления ниже действуют на упражнение с пометкой {0}.',
|
||||
'Full': 'Полная',
|
||||
'Small': 'Малая',
|
||||
'Hidden': 'Скрыта',
|
||||
|
||||
@@ -404,6 +404,12 @@ export default {
|
||||
'Minimize': 'ย่อ',
|
||||
'Expand': 'ขยาย',
|
||||
'Exercise animations': 'ภาพเคลื่อนไหวท่าออกกำลังกาย',
|
||||
'Workout view': 'มุมมองการฝึก',
|
||||
'Cards': 'การ์ด',
|
||||
'List': 'รายการ',
|
||||
'Current': 'ปัจจุบัน',
|
||||
'Set current': 'ตั้งเป็นปัจจุบัน',
|
||||
'Move, swap and remove below act on the exercise marked {0}.': 'การย้าย สลับ และลบด้านล่างจะมีผลกับท่าที่ทำเครื่องหมาย {0} ไว้',
|
||||
'Full': 'เต็ม',
|
||||
'Small': 'เล็ก',
|
||||
'Hidden': 'ซ่อน',
|
||||
|
||||
@@ -394,6 +394,12 @@ export default {
|
||||
'Minimize': 'Küçült',
|
||||
'Expand': 'Büyüt',
|
||||
'Exercise animations': 'Egzersiz animasyonları',
|
||||
'Workout view': 'Antrenman görünümü',
|
||||
'Cards': 'Kartlar',
|
||||
'List': 'Liste',
|
||||
'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.',
|
||||
'Full': 'Tam',
|
||||
'Small': 'Küçük',
|
||||
'Hidden': 'Gizli',
|
||||
|
||||
@@ -394,6 +394,12 @@ export default {
|
||||
'Minimize': '缩小',
|
||||
'Expand': '放大',
|
||||
'Exercise animations': '动作动画',
|
||||
'Workout view': '训练视图',
|
||||
'Cards': '卡片',
|
||||
'List': '列表',
|
||||
'Current': '当前',
|
||||
'Set current': '设为当前',
|
||||
'Move, swap and remove below act on the exercise marked {0}.': '下方的移动、替换和删除将作用于标记为{0}的动作。',
|
||||
'Full': '完整',
|
||||
'Small': '小',
|
||||
'Hidden': '隐藏',
|
||||
|
||||
@@ -14,6 +14,10 @@ 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.
|
||||
workoutView: 'cards',
|
||||
// effort: which per-set effort scale is logged — 'none' | 'rir' | 'rpe'. null, not 'none', so
|
||||
// that a profile which never chose (loaded state is overlaid on DEF, on every path: local,
|
||||
// server pull, backup import) still falls back to the `showRir` boolean this replaced and
|
||||
|
||||
@@ -144,6 +144,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. */}
|
||||
<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'}
|
||||
onChange={v => update(s => { s.workoutView = v })} />
|
||||
</Row>
|
||||
<SelectRow icon="timer" iconTint="var(--orange)" title={t('Rest timer')}
|
||||
value={S.restSec} onChange={v => update(s => { s.restSec = v })}
|
||||
options={[{ value: 0, label: t('Off') }, ...[60, 90, 120, 150, 180].map(v => ({ value: v, label: v + 's' }))]} />
|
||||
|
||||
@@ -0,0 +1,89 @@
|
||||
// @vitest-environment happy-dom
|
||||
import React, { act } from 'react'
|
||||
import { createRoot } from 'react-dom/client'
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
import Settings from './Settings.jsx'
|
||||
|
||||
globalThis.IS_REACT_ACT_ENVIRONMENT = true
|
||||
|
||||
const mocks = vi.hoisted(() => {
|
||||
const state = { S: null }
|
||||
state.snapshot = () => ({
|
||||
S: state.S,
|
||||
user: null,
|
||||
update: mut => {
|
||||
const next = structuredClone(state.S)
|
||||
mut(next)
|
||||
state.S = next
|
||||
},
|
||||
replaceState: vi.fn(), setUser: vi.fn(), pullState: vi.fn(), pushState: vi.fn(),
|
||||
signOut: vi.fn(), signOutAll: vi.fn(), resetDemo: vi.fn(), disconnectServer: vi.fn(),
|
||||
})
|
||||
return state
|
||||
})
|
||||
vi.mock('../store/useStore.js', () => {
|
||||
const useStore = selector => selector ? selector(mocks.snapshot()) : mocks.snapshot()
|
||||
useStore.getState = mocks.snapshot
|
||||
return { useStore, DEF: { reminder: { time: '17:30' } }, hasData: () => false }
|
||||
})
|
||||
vi.mock('../store/useUI.js', () => {
|
||||
const snap = () => ({ toast: vi.fn(), openSheet: vi.fn() })
|
||||
const useUI = selector => selector ? selector(snap()) : snap()
|
||||
useUI.getState = snap
|
||||
return { useUI }
|
||||
})
|
||||
vi.mock('react-router-dom', () => ({ useNavigate: () => () => {} }))
|
||||
vi.mock('../lib/api.js', () => ({
|
||||
api: vi.fn(), webauthnOK: () => false, passkeyLogin: vi.fn(), passkeyRegister: vi.fn(), IS_ANDROID: false,
|
||||
}))
|
||||
vi.mock('../lib/push.js', () => ({ pushSupported: () => false, enablePush: vi.fn(), disablePush: vi.fn(), sendTestPush: vi.fn() }))
|
||||
vi.mock('../lib/wakelock.js', () => ({ wakeLockSupported: () => false }))
|
||||
vi.mock('../lib/mobile.js', () => ({ MOBILE: false, shareExport: vi.fn(), syncReminder: vi.fn() }))
|
||||
vi.mock('./MobileOnboarding.jsx', () => ({ ConnectSheet: () => null }))
|
||||
vi.mock('../sheets.jsx', () => ({
|
||||
loadStarterPlan: vi.fn(), confirmSheet: vi.fn(), importFromApp: vi.fn(),
|
||||
importFromHevy: vi.fn(), equipmentProfileSheet: vi.fn(),
|
||||
}))
|
||||
|
||||
// The Settings view reads the build-time version constant at render time.
|
||||
globalThis.__APP_VERSION__ ??= 'test'
|
||||
|
||||
let host, root
|
||||
beforeEach(() => {
|
||||
mocks.S = {
|
||||
unit: 'kg', restSec: 90, restPauseSec: 15, sound: false, effort: 'none',
|
||||
gifSize: 'full', workouts: [], routines: [], exWeights: {},
|
||||
}
|
||||
host = document.createElement('div')
|
||||
document.body.appendChild(host)
|
||||
root = createRoot(host)
|
||||
})
|
||||
afterEach(() => {
|
||||
act(() => root.unmount())
|
||||
host.remove()
|
||||
})
|
||||
|
||||
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', () => {
|
||||
mount()
|
||||
expect(segButton('Cards')).toBeTruthy()
|
||||
expect(segButton('List')).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('Cards').click() })
|
||||
expect(mocks.S.workoutView).toBe('cards')
|
||||
})
|
||||
|
||||
it('shows a legacy/absent value as Cards', () => {
|
||||
delete mocks.S.workoutView
|
||||
mount()
|
||||
expect(segButton('Cards').getAttribute('aria-pressed')).toBe('true')
|
||||
expect(segButton('List').getAttribute('aria-pressed')).toBe('false')
|
||||
})
|
||||
})
|
||||
@@ -320,6 +320,12 @@ 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'
|
||||
// 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
|
||||
// distinct, while each rendered set index identifies the existing row within that entry.
|
||||
@@ -360,13 +366,13 @@ function ActiveWorkout() {
|
||||
}
|
||||
})
|
||||
useEffect(() => {
|
||||
if (!isSuperset) return
|
||||
if (!isSuperset || listMode) return
|
||||
const entry = A.entries[cur]
|
||||
const firstIncomplete = entry?.sets.findIndex(s => !s.done) ?? -1
|
||||
const setIdx = firstIncomplete >= 0 ? firstIncomplete : (entry?.sets.length ?? 0) - 1
|
||||
const el = (setIdx >= 0 && setRefs.current.get(entry)?.get(setIdx)) || exRefs.current.get(entry)
|
||||
if (el && typeof el.scrollIntoView === 'function') el.scrollIntoView({ behavior: 'smooth', block: 'center' })
|
||||
}, [cur, isSuperset, A.entries.length])
|
||||
}, [cur, isSuperset, listMode, A.entries.length])
|
||||
|
||||
const total = A.entries.reduce((n, e) => n + e.sets.length, 0)
|
||||
const done = setsDoneActive(A)
|
||||
@@ -423,6 +429,17 @@ function ActiveWorkout() {
|
||||
}, true)
|
||||
}
|
||||
|
||||
// One prop object per entry so the card and list layouts share the exact same wiring.
|
||||
const blockProps = idx => ({
|
||||
onToggle: i => toggle(idx, i),
|
||||
onField: (i, f, v) => setField(idx, i, f, v),
|
||||
onAddSet: () => addSet(idx),
|
||||
onRemoveSet: () => removeSet(idx),
|
||||
onAddWarmup: () => addWarmup(idx),
|
||||
onRemoveSetAt: i => removeSetAt(idx, i),
|
||||
onStartTimed: i => startTimed(idx, i),
|
||||
onProgressionSettings: () => openProgressionSettings(idx),
|
||||
})
|
||||
const navigateUnit = direction => {
|
||||
const targetFor = active => {
|
||||
if (!active || !Array.isArray(active.entries) || !Number.isInteger(active.cur)) return null
|
||||
@@ -437,6 +454,10 @@ function ActiveWorkout() {
|
||||
if (target != null) s.active.cur = target
|
||||
})
|
||||
}
|
||||
// List mode shows every unit at once, so the "current" exercise is chosen by tapping
|
||||
// "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 })
|
||||
const onSwipePointerDown = event => {
|
||||
if (swipe.current || (event.pointerType && event.pointerType !== 'touch' && event.pointerType !== 'pen')) return
|
||||
if (event.target.closest?.(SWIPE_IGNORED_TARGETS)) return
|
||||
@@ -640,7 +661,43 @@ function ActiveWorkout() {
|
||||
<div className="wprog"><i style={{ width: (total ? done / total * 100 : 0) + '%' }} /></div>
|
||||
{A.backfill && <div className="muted small" style={{ marginBottom: 8 }}>{t('Logging a past workout — no rest timers.')}</div>}
|
||||
|
||||
{A.entries.length ? <>
|
||||
{A.entries.length ? (listMode ? (
|
||||
<div className="workout-list" data-testid="workout-list">
|
||||
{units.map((u, ui) => {
|
||||
const multi = u.length > 1
|
||||
const isCur = u.includes(cur)
|
||||
return <section key={u.join('-')} className={'wl-unit' + (isCur ? ' cur' : '')} data-exidx={u[0]}>
|
||||
<div className="wl-hd">
|
||||
<span className="muted small">{multi ? t('Superset {0} / {1}', ui + 1, units.length) : t('Exercise {0} / {1}', ui + 1, units.length)}</span>
|
||||
{isCur
|
||||
? <span className="tag acc">{t('Current')}</span>
|
||||
: <button className="chip" onClick={() => focusUnit(u[0])}>{t('Set current')}</button>}
|
||||
</div>
|
||||
{multi ? (
|
||||
<div className="ss-card">
|
||||
<div className="ss-hd" style={{ justifyContent: 'space-between' }}>
|
||||
<span className="row" style={{ gap: 5 }}><Icon name="link" />{t('Superset · do these back-to-back, rest when done')}</span>
|
||||
<Button size="xs" variant="ghost" icon="link" title={t('Unpair')} onClick={() => unpairAt(u[0])}>{t('Unpair')}</Button>
|
||||
</div>
|
||||
{u.map((idx, k) => {
|
||||
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)}
|
||||
{...blockProps(idx)} />
|
||||
</div>
|
||||
})}
|
||||
</div>
|
||||
) : (
|
||||
<ExerciseBlock entryIdx={u[0]}
|
||||
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])} />
|
||||
)}
|
||||
</section>
|
||||
})}
|
||||
</div>
|
||||
) : <>
|
||||
<div className="muted small" style={{ marginBottom: 6 }}>{isSuperset ? t('Superset {0} / {1}', unitIdx + 1, units.length) : t('Exercise {0} / {1}', unitIdx + 1, units.length)}</div>
|
||||
<div className="workout-swipe-surface" data-testid="workout-swipe-surface"
|
||||
onPointerDown={onSwipePointerDown}
|
||||
@@ -660,22 +717,23 @@ function ActiveWorkout() {
|
||||
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)}
|
||||
onToggle={i => toggle(idx, i)} onField={(i, f, v) => setField(idx, i, f, v)} onAddSet={() => addSet(idx)} onRemoveSet={() => removeSet(idx)} onAddWarmup={() => addWarmup(idx)} onRemoveSetAt={i => removeSetAt(idx, i)} onStartTimed={i => startTimed(idx, i)} onProgressionSettings={() => openProgressionSettings(idx)} />
|
||||
{...blockProps(idx)} />
|
||||
</div>
|
||||
})}
|
||||
</div>
|
||||
) : (
|
||||
<ExerciseBlock entryIdx={cur} onToggle={i => toggle(cur, i)} onField={(i, f, v) => setField(cur, i, f, v)} onAddSet={() => addSet(cur)} onRemoveSet={() => removeSet(cur)} onAddWarmup={() => addWarmup(cur)} onRemoveSetAt={i => removeSetAt(cur, i)} onStartTimed={i => startTimed(cur, i)} onPairPrev={onPairPrev} onPairNext={onPairNext} onProgressionSettings={() => openProgressionSettings(cur)} />
|
||||
<ExerciseBlock entryIdx={cur} onPairPrev={onPairPrev} onPairNext={onPairNext} {...blockProps(cur)} />
|
||||
)}
|
||||
</div>
|
||||
</> : <div className="empty"><div className="ico"><Icon name="shuffle" /></div>{t('Freestyle workout — add your first exercise.')}</div>}
|
||||
</>) : <div className="empty"><div className="ico"><Icon name="shuffle" /></div>{t('Freestyle workout — add your first exercise.')}</div>}
|
||||
|
||||
<div style={{ height: 12 }} />
|
||||
<div className="row">
|
||||
{!listMode && <div className="row">
|
||||
<Button icon="chevronLeft" disabled={unitIdx <= 0} onClick={() => navigateUnit(-1)}>{t('Prev')}</Button>
|
||||
<Button trailingIcon="chevronRight" disabled={unitIdx < 0 || unitIdx >= units.length - 1} onClick={() => navigateUnit(1)}>{t('Next')}</Button>
|
||||
</div>
|
||||
<div style={{ height: 10 }} />
|
||||
</div>}
|
||||
{!listMode && <div style={{ height: 10 }} />}
|
||||
{listMode && A.entries.length > 0 && <div className="muted small" style={{ marginBottom: 6 }}>{t('Move, swap and remove below act on the exercise marked {0}.', t('Current'))}</div>}
|
||||
<Button onClick={() => exercisePicker(ex => {
|
||||
const routine = S.routines.find(r => r.id === A.routineId)
|
||||
const freestyle = !A.routineId
|
||||
|
||||
@@ -697,3 +697,75 @@ describe('active exercise swap control', () => {
|
||||
expect(mocks.swapActiveWorkoutExercise).toHaveBeenCalledWith(1)
|
||||
})
|
||||
})
|
||||
|
||||
describe('workout list view', () => {
|
||||
const units = () => [...container.querySelectorAll('.wl-unit')]
|
||||
const focusButton = unit => [...unit.querySelectorAll('button')].find(b => b.textContent.trim() === 'Set current')
|
||||
|
||||
it('stacks every exercise, labels each unit, and hides card navigation', async () => {
|
||||
await mount([exercise('plain-bench', [false, false]), exercise('plain-row', [false])], 0, { workoutView: 'list' })
|
||||
|
||||
expect(container.querySelector('[data-testid="workout-list"]')).toBeTruthy()
|
||||
expect(container.querySelector('[data-testid="workout-swipe-surface"]')).toBeNull()
|
||||
expect(units().length).toBe(2)
|
||||
// Every set in the session is visible at once: 2 + 1 checkboxes, not just the current one.
|
||||
expect(container.querySelectorAll('[role="checkbox"]').length).toBe(3)
|
||||
expect(units().map(u => u.querySelector('.wl-hd .muted')?.textContent)).toEqual([
|
||||
'Exercise 1 / 2', 'Exercise 2 / 2',
|
||||
])
|
||||
expect(units()[0].textContent).toContain('Current')
|
||||
expect(focusButton(units()[1])).toBeTruthy()
|
||||
const navButtons = [...container.querySelectorAll('button')]
|
||||
.filter(b => b.textContent.trim() === 'Prev' || b.textContent.trim() === 'Next')
|
||||
expect(navButtons.length).toBe(0)
|
||||
})
|
||||
|
||||
it('marks the current unit and moves the mark with Set current', async () => {
|
||||
await mount([exercise('plain-bench', [false]), exercise('plain-row', [false])], 0, { workoutView: 'list' })
|
||||
|
||||
await act(async () => { focusButton(units()[1]).dispatchEvent(new dom.Event('click', { bubbles: true })) })
|
||||
expect(mocks.S.active.cur).toBe(1)
|
||||
|
||||
await rerender()
|
||||
expect(units()[0].textContent).not.toContain('Current')
|
||||
expect(units()[1].textContent).toContain('Current')
|
||||
expect(focusButton(units()[0])).toBeTruthy()
|
||||
})
|
||||
|
||||
it('completing a set in list mode advances the current exercise like cards do', async () => {
|
||||
await mount([
|
||||
exercise('plain-bench', [false], { asked: true }),
|
||||
exercise('plain-row', [false], { asked: true }),
|
||||
], 0, { workoutView: 'list' })
|
||||
|
||||
await toggleSet(0)
|
||||
|
||||
expect(mocks.S.active.entries[0].sets[0].done).toBe(true)
|
||||
expect(mocks.S.active.cur).toBe(1)
|
||||
expect(mocks.startRest).toHaveBeenCalledWith(90, expect.any(Number))
|
||||
})
|
||||
|
||||
it('renders a superset as one grouped unit with its own unpair control', async () => {
|
||||
await mount([
|
||||
exercise('bench', [false], { sg: 'g1', asked: true }),
|
||||
exercise('row', [false], { sg: 'g1', asked: true }),
|
||||
exercise('squat', [false], { asked: true }),
|
||||
], 0, { workoutView: 'list' })
|
||||
|
||||
expect(units().length).toBe(2)
|
||||
expect(units()[0].querySelector('.ss-card')).toBeTruthy()
|
||||
expect(units()[1].querySelector('.ss-card')).toBeNull()
|
||||
expect(units().map(u => u.querySelector('.wl-hd .muted')?.textContent)).toEqual([
|
||||
'Superset 1 / 2', 'Exercise 2 / 2',
|
||||
])
|
||||
})
|
||||
|
||||
it('defaults to cards when the setting is absent (pre-existing profiles)', async () => {
|
||||
await mount([exercise('plain-bench', [false]), exercise('plain-row', [false])])
|
||||
|
||||
expect(container.querySelector('[data-testid="workout-list"]')).toBeNull()
|
||||
expect(container.querySelector('[data-testid="workout-swipe-surface"]')).toBeTruthy()
|
||||
// Only the current exercise's sets are on screen.
|
||||
expect(container.querySelectorAll('[role="checkbox"]').length).toBe(1)
|
||||
})
|
||||
})
|
||||
Reference in new issue
Block a user