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.
JavaScript apple-watchbodyweightdockerfitnessfitness-trackergymhealthiosmcpnodejspasskeysprogressive-web-applicationspwareactself-hostedself-hostingvitewebauthnweightliftingworkout-tracker
curated2: !41 (a move re-points the rest countdown instead of cancelling it)
Duarte Santos250b164d2d07
diff --cc frontend/src/views/Workout.jsxindex a74c3bdef,0074f6337..a3e6ca599--- a/frontend/src/views/Workout.jsx+++ b/frontend/src/views/Workout.jsx@@@ -16,11 -16,8 +16,12 @@@ import { Button, Check, NumberField } fimport { nextPrescription, applyPrescription, defaultIncrement } from '../lib/progression.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() {const nav = useNavigate()@@@ -379,39 -335,19 +380,57 @@@ function ActiveWorkout()})const onPairPrev = !isSuperset && cur > 0 ? () => pairAt(cur - 1, cur) : nullconst 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, and cancel a displaced rest timer.++ // 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()- ui.stopRest()+ update(s => {+ const moved = moveActiveWorkoutUnit(s.active, s.active?.cur, direction)- if (moved) progressHighWater.current = moved.indices.map(index => progressHighWater.current[index])++ 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)+ }+// 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 = removeActiveExercisediff --cc frontend/src/views/Workout.test.jsxindex 664261306,9278c6adc..ffb01e1b7--- a/frontend/src/views/Workout.test.jsx+++ b/frontend/src/views/Workout.test.jsx@@@ -455,65 -188,64 +455,123 @@@ 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]).toBe(selected)++ 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()+ })++ 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).toBe(groupMeta)- expect(mocks.S.active.entries[mocks.S.active.cur]).toBe(selected)++ 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)+ })+ })