Skip to content

Open-source gym & body-weight tracker, now in the App Store (iPhone + Apple Watch) and as an Android APK. Plan routines, log workouts, see which muscles are trained, import from Strong/Hevy/FitNotes. Self-host it or use it on the phone alone.

curated2: !54

Duarte Santos41286db2443e
diff --cc frontend/src/views/Workout.jsx
index 65a5de4c6,b645c92a5..25be741e6
--- a/frontend/src/views/Workout.jsx
+++ b/frontend/src/views/Workout.jsx
@@@ -14,13 -14,9 +14,14 @@@ import { startFlow, exercisePicker, exC
import Icon from '../components/Icon.jsx'
import { Button, Check, NumberField } from '../components/ui.jsx'
import { nextPrescription, applyPrescription, defaultIncrement } from '../lib/progression.js'
+ import { progressionGuidance } from '../lib/progression-copy.js'
import { glyphOf } from '../lib/glyphs.js'
import { isWarmupRow, isDropSet, isRestPauseSet, dropsOf, clustersOf, addDrop, addCluster, removeDropAt, removeClusterAt, setDropAt, setClusterAt, nextDropWeight, nextBurstReps } from '../lib/workout-model.js'
+import { canMoveActiveWorkoutUnit, moveActiveWorkoutUnit } from '../lib/active-workout-order.js'
+
+const SWIPE_MIN_DISTANCE = 48
+const SWIPE_AXIS_RATIO = 1.25
+const SWIPE_IGNORED_TARGETS = 'button,input,textarea,select,a,[role="button"],[role="checkbox"],[role="switch"],[role="slider"],[contenteditable="true"],.exmedia,[data-swipe-ignore]'
/* ---------- start chooser (no active workout) ---------- */
function StartChooser() {
@@@ -61,7 -57,7 +62,7 @@@ 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 }) {
-function ExerciseBlock({ entryIdx, compact, onToggle, onField, onAddSet, onRemoveSet, onAddWarmup, onRemoveSetAt, onStartTimed, onPairPrev, onPairNext, onProgressionSettings }) {
++function ExerciseBlock({ entryIdx, compact, onToggle, onField, onAddSet, onRemoveSet, onAddWarmup, onRemoveSetAt, onStartTimed, onPairPrev, onPairNext, onSetRowRef, onProgressionSettings }) {
const S = useStore(s => s.S)
const update = useStore(s => s.update)
const working = useUI(s => s.work)
@@@ -380,57 -337,24 +383,74 @@@ function ActiveWorkout()
})
const onPairPrev = !isSuperset && cur > 0 ? () => pairAt(cur - 1, cur) : null
const onPairNext = !isSuperset && cur < A.entries.length - 1 ? () => pairAt(cur, cur + 1) : null
+ const moveCurrentUnit = direction => {
+ const ui = useUI.getState()
+ const active = useStore.getState().S.active
+ if (ui.work || !canMoveActiveWorkoutUnit(active, active?.cur, direction)) return
+ // Invalidate an old timed callback before indexes shift. A running rest is not cancelled:
+ // it belongs to an exercise (timer.forIdx), and that exercise only changes position.
+ ui.stopWork()
+ update(s => {
+ const moved = moveActiveWorkoutUnit(s.active, s.active?.cur, direction)
+ if (!moved) return
+ progressHighWater.current = moved.indices.map(index => progressHighWater.current[index])
+ const rest = useUI.getState().timer
+ if (rest && rest.forIdx != null) {
+ const forIdx = moved.indices.indexOf(rest.forIdx)
+ if (forIdx >= 0) useUI.setState({ timer: { ...rest, forIdx } })
+ }
+ }, true)
+ }
+
+ const navigateUnit = direction => {
+ const targetFor = active => {
+ if (!active || !Array.isArray(active.entries) || !Number.isInteger(active.cur)) return null
+ if (active.cur < 0 || active.cur >= active.entries.length) return null
+ const freshUnits = supersetUnits(active.entries)
+ const freshUnitIdx = freshUnits.findIndex(candidate => candidate.includes(active.cur))
+ return freshUnitIdx < 0 ? null : freshUnits[freshUnitIdx + direction]?.[0] ?? null
+ }
+ if (targetFor(useStore.getState().S.active) == null) return
+ update(s => {
+ const target = targetFor(s.active)
+ if (target != null) s.active.cur = target
+ })
+ }
+ const onSwipePointerDown = event => {
+ if (swipe.current || (event.pointerType && event.pointerType !== 'touch' && event.pointerType !== 'pen')) return
+ if (event.target.closest?.(SWIPE_IGNORED_TARGETS)) return
+ swipe.current = { id: event.pointerId, x: event.clientX, y: event.clientY }
+ event.currentTarget.setPointerCapture?.(event.pointerId)
+ }
+ const finishSwipe = (event, navigate) => {
+ const start = swipe.current
+ if (!start || start.id !== event.pointerId) return
+ swipe.current = null
+ event.currentTarget.releasePointerCapture?.(event.pointerId)
+ if (!navigate) return
+ const dx = event.clientX - start.x
+ const dy = event.clientY - start.y
+ if (Math.abs(dx) < SWIPE_MIN_DISTANCE || Math.abs(dx) < Math.abs(dy) * SWIPE_AXIS_RATIO) return
+ navigateUnit(dx < 0 ? 1 : -1)
+ }
+ const openProgressionSettings = idx => {
+ const state = useStore.getState().S
+ const entry = state.active?.entries?.[idx]
+ if (!entry) return
+ const routine = state.routines.find(r => r.id === state.active.routineId)
+ exConfigSheet(exOr(entry.id), entry.target, cfg => update(s => {
+ const activeEntry = s.active?.entries?.[idx]
+ if (!activeEntry) return
+ const full = { ...cfg, id: activeEntry.id }
+ const activeRoutine = s.routines.find(r => r.id === s.active.routineId)
+ const plan = nextPrescription(s, full, activeRoutine)
+ activeEntry.target = { ...cfg }
+ activeEntry.plan = plan
+ activeEntry.sets = applyPrescription(activeEntry.sets, plan, defaultIncrement(activeEntry.id, s.unit))
+ }), null, routine)
+ }
+
// Remove a whole exercise from the session. The confirmation always asks first; in a
// superset it asks WHICH exercise of the group to remove.
const removeExercise = removeActiveExercise
@@@ -598,19 -513,15 +618,19 @@@
<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(cur)}>{t('Unpair')}</Button>
</div>
- {unit.map((idx, k) => <div key={idx} ref={el => { exRefs.current[idx] = el }} className="ss-ex" data-exidx={idx}>
- {k > 0 && <div className="ss-amp">+</div>}
- <ExerciseBlock entryIdx={idx} compact
- 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)} />
- </div>)}
+ {unit.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)}
- 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)} />
++ 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)} />
+ </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} />
+ <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)} />
)}
+ </div>
</> : <div className="empty"><div className="ico"><Icon name="shuffle" /></div>{t('Freestyle workout — add your first exercise.')}</div>}
<div style={{ height: 12 }} />
diff --cc frontend/src/views/Workout.test.jsx
index dd17e030d,7f8286fb9..72c008299
--- a/frontend/src/views/Workout.test.jsx
+++ b/frontend/src/views/Workout.test.jsx
@@@ -137,41 -117,15 +137,48 @@@ async function toggleSet(index)
await act(async () => { checkbox.dispatchEvent(new dom.Event('click', { bubbles: true })) })
}
+ async function pressProgression(index = 0) {
+ const button = container.querySelectorAll('.progline')[index]
+ expect(button).toBeTruthy()
+ await act(async () => { button.dispatchEvent(new dom.Event('click', { bubbles: true })) })
+ return button
+ }
+
+async function requestDiscard() {
+ const button = container.querySelector('button[aria-label="Discard"]')
+ expect(button).toBeTruthy()
+ await act(async () => { button.dispatchEvent(new dom.Event('click', { bubbles: true })) })
+}
+
+async function rerender() {
+ await act(async () => { root.render(React.createElement(Workout)) })
+}
+
+async function addExerciseThroughSheets(ex = { id: 'added-exercise' }, cfg = { mode: 'reps', sets: 1, reps: 5, weight: 0 }) {
+ const addButton = [...container.querySelectorAll('button')]
+ .find(button => button.textContent.trim() === 'Add exercise')
+ expect(addButton).toBeTruthy()
+ await act(async () => { addButton.dispatchEvent(new dom.Event('click', { bubbles: true })) })
+
+ const pickerCall = mocks.exercisePicker.mock.calls.at(-1)
+ expect(pickerCall?.[0]).toEqual(expect.any(Function))
+ await act(async () => { pickerCall[0](ex) })
+
+ const configCall = mocks.exConfigSheet.mock.calls.at(-1)
+ expect(configCall?.[2]).toEqual(expect.any(Function))
+ await act(async () => { configCall[2](cfg) })
+}
+
+async function rerenderAt(cur) {
+ mocks.S.active.cur = cur
+ await act(async () => { root.render(React.createElement(Workout)) })
+}
+
beforeEach(() => {
vi.clearAllMocks()
+ mocks.timer = null
+ mocks.work = null
+ mocks.scrollCalls.length = 0
})
afterEach(async () => {
@@@ -428,6 -167,106 +435,106 @@@ describe('Workout discard timer lifecyc
})
})
+ describe('progression guidance', () => {
+ it('labels the visible outcome with the policy that calculated it', async () => {
+ await mount([exercise('plain-bench', [false, false, false], {
+ plan: {
+ policy: 'linear',
+ kind: 'up',
+ weight: 62.5,
+ why: ['Every rep last time — {0} {1} more.', 2.5, 'kg'],
+ },
+ })])
+
+ expect(container.querySelector('.progline')?.textContent)
+ .toContain('Linear progression · Every rep last time — 2.5 kg more.')
+ })
+
+ it('is a keyboard-accessible button that opens settings for the pressed grouped entry', async () => {
+ const plan = {
+ policy: 'linear', kind: 'up', weight: 62.5,
+ why: ['Every rep last time — {0} {1} more.', 2.5, 'kg'],
+ }
+ const first = exercise('plain-bench', [false], { sg: 'group', plan })
+ const second = exercise('plain-bench', [false], {
+ sg: 'group', plan, target: { mode: 'reps', reps: 8, weight: 80, bodyweight: false },
+ })
+ await mount([first, second])
+ const firstBefore = JSON.stringify(mocks.S.active.entries[0])
+
+ const button = await pressProgression(1)
+
+ expect(button.tagName).toBe('BUTTON')
+ expect(button.getAttribute('type')).toBe('button')
+ expect(button.getAttribute('aria-label')).toBe('Open progression settings')
+ expect(mocks.exConfigSheet).toHaveBeenCalledOnce()
+ expect(mocks.exConfigSheet.mock.calls[0][1]).toBe(second.target)
+ expect(mocks.exConfigSheet.mock.calls[0][4]).toBe(mocks.S.routines[0])
+
+ mocks.exConfigSheet.mock.calls[0][2]({ ...second.target, prog: 'double', repsMin: 6 })
+ expect(JSON.stringify(mocks.S.active.entries[0])).toBe(firstBefore)
+ expect(mocks.S.active.entries[1].target.prog).toBe('double')
+ expect(mocks.S.active.cur).toBe(0)
+ })
+
+ it('leaves the active entry unchanged when progression settings are cancelled', async () => {
+ const entry = exercise('plain-bench', [true, false], {
+ plan: {
+ policy: 'linear', kind: 'up', weight: 62.5,
+ why: ['Every rep last time — {0} {1} more.', 2.5, 'kg'],
+ },
+ })
+ await mount([entry])
+ const before = JSON.stringify(mocks.S.active.entries[0])
+
+ await pressProgression()
+
+ expect(JSON.stringify(mocks.S.active.entries[0])).toBe(before)
+ })
+
+ it('saves the active policy, preserves completed rows, and refreshes guidance immediately', async () => {
+ const entry = exercise('plain-bench', [true, false], {
+ plan: {
+ policy: 'linear', kind: 'up', weight: 62.5,
+ why: ['Every rep last time — {0} {1} more.', 2.5, 'kg'],
+ },
+ })
+ await mount([entry])
+ mocks.S.workouts = [{
+ d: '2026-08-27',
+ entries: [{
+ id: entry.id,
+ target: { sets: 2, reps: 5, weight: 60 },
+ sets: [{ w: 60, r: 5, done: true }, { w: 60, r: 5, done: true }],
+ }],
+ }]
+ const completed = mocks.S.active.entries[0].sets[0]
+ await pressProgression()
+ const save = mocks.exConfigSheet.mock.calls[0][2]
+
+ await act(async () => {
+ save({ ...entry.target, prog: 'double', repsMin: 3 })
+ root.render(React.createElement(Workout))
+ })
+
+ const saved = mocks.S.active.entries[0]
+ expect(saved.target.prog).toBe('double')
- expect(saved.sets[0]).toBe(completed)
++ expect(saved.sets[0]).toEqual(completed)
+ expect(saved.sets[0]).toEqual({ w: 60, r: 5, done: true })
+ expect(saved.sets[1]).toEqual({ w: 62.5, r: 3, done: false })
+ expect(container.querySelector('.progline')?.textContent)
+ .toContain('Double progression · Top of the rep range in every set — 2.5 kg more, back to 3 reps.')
+
+ const persisted = JSON.parse(JSON.stringify(mocks.S))
+ await unmount()
+ mocks.S = persisted
+ installDom()
+ await act(async () => { root.render(React.createElement(Workout)) })
+ expect(container.querySelector('.progline')?.textContent)
+ .toContain('Double progression · Top of the rep range in every set — 2.5 kg more, back to 3 reps.')
+ })
+ })
+
describe('superset flow survives an exercise being removed mid-session', () => {
// removeActiveExercise splices A.entries, shifting every index above the removal down.
// The high-water marks are index-keyed, so without re-baselining the shifted exercise