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: !43

Duarte Santos0e3b8fa74b72
diff --cc frontend/src/sheets.jsx
index 7ce77be2d,feff6e14a..00509b5b5
--- a/frontend/src/sheets.jsx
+++ b/frontend/src/sheets.jsx
@@@ -24,7 -23,7 +24,8 @@@ import { nextPrescription, applyPrescri
import { MOBILE, shareExport } from './lib/mobile.js'
import { buildCompletedWorkout } from './lib/finish-workout.js'
import { isWarmupRow } from './lib/workout-model.js'
+import { nextUnfinishedUnit } from './lib/supersetFlow.js'
+ import { swapActiveExercise } from './lib/active-exercise-swap.js'
const S = () => useStore.getState().S
const update = (...a) => useStore.getState().update(...a)
diff --cc frontend/src/views/Workout.jsx
index a3e6ca599,fe21acb0c..65a5de4c6
--- a/frontend/src/views/Workout.jsx
+++ b/frontend/src/views/Workout.jsx
@@@ -8,9 -8,9 +8,9 @@@ import { fmtNum, fmtDate, todayISO, exC
import { beep, vibrate } from '../lib/sound.js'
import { t, exerciseNameFor } from '../lib/i18n.js'
import { api } from '../lib/api.js'
-import { setProgressHighWater, supersetFlowStep, restAfterSet, restOnRecheck } from '../lib/supersetFlow.js'
+import { insertionIndexAfterCurrentUnit, nextUnfinishedUnit, setProgressHighWater, supersetFlowStep, restAfterSet, restOnRecheck } from '../lib/supersetFlow.js'
import Media from '../components/Media.jsx'
- import { startFlow, exercisePicker, exConfigSheet, exerciseDetailSheet, topWeightSheet, finishWorkout, workoutCompleteSheet, confirmSheet, exerciseNoteSheet, sessionNoteSheet } from '../sheets.jsx'
+ import { startFlow, exercisePicker, exConfigSheet, exerciseDetailSheet, topWeightSheet, finishWorkout, workoutCompleteSheet, confirmSheet, exerciseNoteSheet, sessionNoteSheet, swapActiveWorkoutExercise } from '../sheets.jsx'
import Icon from '../components/Icon.jsx'
import { Button, Check, NumberField } from '../components/ui.jsx'
import { nextPrescription, applyPrescription, defaultIncrement } from '../lib/progression.js'
@@@ -637,14 -526,12 +637,19 @@@ function ActiveWorkout()
}), null, routine, seed)
})} icon="plus">{t('Add exercise')}</Button>
{A.entries.length > 0 && <>
+ <div style={{ height: 6 }} />
+ <div className="row">
+ <Button size="sm" icon="chevronUp" aria-label={t('Move up')}
+ disabled={!!work || !canMoveActiveWorkoutUnit(A, cur, -1)} onClick={() => moveCurrentUnit(-1)}>{t('Move up')}</Button>
+ <Button size="sm" trailingIcon="chevronDown" aria-label={t('Move down')}
+ disabled={!!work || !canMoveActiveWorkoutUnit(A, cur, 1)} onClick={() => moveCurrentUnit(1)}>{t('Move down')}</Button>
+ </div>
<div style={{ height: 6 }} />
+ <div style={{ display: 'flex', justifyContent: 'center' }}>
+ <Button size="sm" icon="shuffle" aria-label={t('Swap exercise')} disabled={!!work}
+ onClick={() => swapActiveWorkoutExercise(cur)}>{t('Swap exercise')}</Button>
+ </div>
+ <div style={{ height: 6 }} />
<div style={{ display: 'flex', justifyContent: 'center' }}>
<Button size="sm" icon="minus" style={{ color: 'var(--red)' }} disabled={!!work} onClick={removeExerciseSheet}>{t('Remove exercise')}</Button>
</div>
diff --cc frontend/src/views/Workout.test.jsx
index ffb01e1b7,dcd24f247..dd17e030d
--- a/frontend/src/views/Workout.test.jsx
+++ b/frontend/src/views/Workout.test.jsx
@@@ -7,21 -7,11 +7,22 @@@ import Workout from './Workout.jsx
const mocks = vi.hoisted(() => {
const state = {
S: null,
+ timer: null,
+ work: null,
startRest: vi.fn(),
- stopRest: vi.fn(),
+ stopRest: null,
+ stopWork: null,
+ confirmSheet: vi.fn(),
topWeightSheet: vi.fn(),
+ workoutCompleteSheet: vi.fn(),
+ exercisePicker: vi.fn(),
+ exConfigSheet: vi.fn(),
+ toast: vi.fn(),
+ scrollCalls: [],
+ swapActiveWorkoutExercise: vi.fn(),
}
+ state.stopRest = vi.fn(() => { state.timer = null })
+ state.stopWork = vi.fn(() => { state.work = null })
state.storeSnapshot = () => ({
S: state.S,
user: null,
@@@ -62,8 -45,9 +63,9 @@@ vi.mock('../sheets.jsx', () => (
exerciseDetailSheet: vi.fn(),
topWeightSheet: mocks.topWeightSheet,
finishWorkout: vi.fn(),
- workoutCompleteSheet: vi.fn(),
- confirmSheet: vi.fn(),
+ workoutCompleteSheet: mocks.workoutCompleteSheet,
+ confirmSheet: mocks.confirmSheet,
+ swapActiveWorkoutExercise: mocks.swapActiveWorkoutExercise,
// Both note sheets belong here even though the tests never open one: Workout.jsx reads
// sessionNoteSheet during render, so a missing export is a render crash, not a no-op.
exerciseNoteSheet: vi.fn(),
@@@ -455,123 -186,19 +457,136 @@@ describe('superset flow survives an exe
// Partner closes the round (each still has a second set), which is what starts the rest.
await toggleSet(2)
- expect(mocks.startRest).toHaveBeenCalledWith(90)
+ expect(mocks.startRest).toHaveBeenCalledWith(90, expect.any(Number))
+ })
+})
+
+describe('superset actionable-set centring', () => {
+ it('centres the newly active exercise first incomplete set row', async () => {
+ await mount([
+ exercise('bench', [true, false], { sg: 'g1' }),
+ exercise('row', [true, false, false], { sg: 'g1' }),
+ ])
+ mocks.scrollCalls.length = 0
+
+ await rerenderAt(1)
+
+ const rows = container.querySelector('[data-exidx="1"]').querySelectorAll('.setrow')
+ expect(mocks.scrollCalls).toEqual([
+ { node: rows[1], options: { behavior: 'smooth', block: 'center' } },
+ ])
+ })
+
+ it('centres the last set row when the newly active exercise is complete', async () => {
+ await mount([
+ exercise('bench', [true, false], { sg: 'g1' }),
+ exercise('row', [true, true], { sg: 'g1' }),
+ ])
+ mocks.scrollCalls.length = 0
+
+ await rerenderAt(1)
+
+ const rows = container.querySelector('[data-exidx="1"]').querySelectorAll('.setrow')
+ expect(mocks.scrollCalls).toEqual([
+ { node: rows[1], options: { behavior: 'smooth', block: 'center' } },
+ ])
+ })
+
+ it('centres the exercise wrapper when the newly active exercise has no set row', async () => {
+ await mount([
+ exercise('bench', [true, false], { sg: 'g1' }),
+ exercise('row', [], { sg: 'g1' }),
+ ])
+ mocks.scrollCalls.length = 0
+
+ await rerenderAt(1)
+
+ const wrapper = container.querySelector('[data-exidx="1"]')
+ expect(mocks.scrollCalls).toEqual([
+ { node: wrapper, options: { behavior: 'smooth', block: 'center' } },
+ ])
+ })
+
+ it('does not auto-scroll set rows for ordinary exercise navigation', async () => {
+ await mount([
+ exercise('bench', [true, false]),
+ exercise('row', [false, false]),
+ ])
+ mocks.scrollCalls.length = 0
+
+ await rerenderAt(1)
+
+ expect(mocks.scrollCalls).toEqual([])
+ })
+})
+
+describe('active workout whole-unit move controls', () => {
+ const action = label => container.querySelector(`button[aria-label="${label}"]`)
+
+ it('shows labelled controls and moves the selected standalone exercise one unit', async () => {
+ const selected = exercise('duplicate', [false], {
+ occurrenceId: 'duplicate#2',
+ target: { mode: 'reps', reps: 7, weight: 82.5, notes: 'Keep this target' },
+ sets: [{ w: 77.5, r: 6, done: true, rir: 2 }],
+ })
+ await mount([
+ exercise('duplicate', [false], { occurrenceId: 'duplicate#1' }),
+ exercise('middle', [false]),
+ selected,
+ ], 2)
+
+ expect(action('Move up')?.textContent.trim()).toBe('Move up')
+ expect(action('Move down')?.textContent.trim()).toBe('Move down')
+ await act(async () => { action('Move up').dispatchEvent(new dom.Event('click', { bubbles: true })) })
+
+ expect(mocks.S.active.entries.map(entry => entry.occurrenceId || entry.id)).toEqual(['duplicate#1', 'duplicate#2', 'middle'])
+ expect(mocks.S.active.entries[1]).toEqual(selected)
+ expect(mocks.S.active.entries[1].target).toEqual({ mode: 'reps', reps: 7, weight: 82.5, notes: 'Keep this target' })
+ expect(mocks.S.active.entries[1].sets).toEqual([{ w: 77.5, r: 6, done: true, rir: 2 }])
+ expect(mocks.S.active.cur).toBe(1)
+ expect(mocks.stopWork).toHaveBeenCalledOnce()
- expect(mocks.stopRest).toHaveBeenCalledOnce()
++ expect(mocks.stopRest).not.toHaveBeenCalled()
+ })
+
+ it('moves the selected contiguous group as one unit without changing its metadata', async () => {
+ const first = exercise('group-a', [false], { sg: 'pair', occurrenceId: 'group-a#1' })
+ const selected = exercise('group-b', [true], { sg: 'pair', occurrenceId: 'group-b#1' })
+ const groupMeta = { pair: { kind: 'complex', label: 'Carry pair', cues: 'Stay braced.' } }
+ await mount([
+ exercise('before', [false]),
+ first,
+ selected,
+ exercise('after', [false]),
+ ], 2)
+ mocks.S.active.groupMeta = groupMeta
+
+ await act(async () => { action('Move up').dispatchEvent(new dom.Event('click', { bubbles: true })) })
+
+ expect(mocks.S.active.entries.map(entry => entry.id)).toEqual(['group-a', 'group-b', 'before', 'after'])
+ expect(mocks.S.active.entries.slice(0, 2)).toEqual([first, selected])
+ expect(mocks.S.active.entries.slice(0, 2).map(entry => entry.sg)).toEqual(['pair', 'pair'])
+ expect(mocks.S.active.groupMeta).toEqual(groupMeta)
+ expect(mocks.S.active.entries[mocks.S.active.cur]).toEqual(selected)
+ })
+
+ it('disables both moves while a work timer can still write by index', async () => {
+ mocks.work = { left: 5, total: 5, endsAt: Date.now() + 5000 }
+ await mount([exercise('first', [false]), exercise('second', [false])], 1)
+
+ expect(action('Move up')?.disabled).toBe(true)
+ expect(action('Move down')?.disabled).toBe(true)
})
})
+
+ describe('active exercise swap control', () => {
+ it('opens the swap flow for the selected duplicate occurrence', async () => {
+ await mount([exercise('bench', [false]), exercise('bench', [false]), exercise('row', [false])], 1)
+
+ const swap = container.querySelector('button[aria-label="Swap exercise"]')
+ expect(swap).toBeTruthy()
+ await act(async () => { swap.dispatchEvent(new dom.Event('click', { bubbles: true })) })
+
+ expect(mocks.swapActiveWorkoutExercise).toHaveBeenCalledOnce()
+ expect(mocks.swapActiveWorkoutExercise).toHaveBeenCalledWith(1)
+ })
+ })