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
Timed exercises: the next exercise comes up when the last rest runs out (#532)
Duarte Santosde04b7f95363
diff --git a/frontend/src/lib/supersetFlow.js b/frontend/src/lib/supersetFlow.jsindex cc2734050..e982d8b0e 100644--- a/frontend/src/lib/supersetFlow.js+++ b/frontend/src/lib/supersetFlow.js@@ -163,3 +163,21 @@ export function supersetFlowStep(entries, unit, fromIdx) {const roundDone = !unit.slice(pos + 1).some(idx => hasWork(entries, idx))return { unitDone: false, roundDone, nextIdx }}++/**+ * Where Cards and Focus move on their own once the rest after a timed exercise's last set has run+ * out (#532): a plank or an L-sit has nothing to adjust before the next exercise, so the screen+ * goes there without a tap. Only when every exercise of the unit the rest was for is timed+ * (`isTimed(idx)`) and finished, and that unit is still the one on screen; then the next unit with+ * work left (nextUnfinishedUnit), its first exercise. null for anything else: weighted work still+ * waits for Next, as before.+ */+export function advanceAfterTimedRest(entries, units, forIdx, cur, isTimed) {+ if (!Array.isArray(entries) || !Array.isArray(units) || !Number.isInteger(forIdx)) return null+ const unit = units.find(u => u.includes(forIdx))+ if (!unit || !unit.includes(cur)) return null+ if (!unit.every(idx => isTimed(idx) && (entries[idx]?.sets || []).length > 0 && !hasWork(entries, idx))) return null+ const next = nextUnfinishedUnit(entries, units, forIdx)+ return next ? next[0] : null+}+diff --git a/frontend/src/lib/supersetFlow.test.js b/frontend/src/lib/supersetFlow.test.jsindex dcbc10730..c674201f9 100644--- a/frontend/src/lib/supersetFlow.test.js+++ b/frontend/src/lib/supersetFlow.test.js@@ -1,5 +1,5 @@import { describe, expect, it } from 'vitest'-import { insertionIndexAfterCurrentUnit, nextUnfinishedUnit, setProgressHighWater, supersetFlowStep, restAfterSet, restOnRecheck, restSecFor, warmupRestSecFor, sideRestFor, stepUnitIndex } from './supersetFlow.js'+import { insertionIndexAfterCurrentUnit, nextUnfinishedUnit, setProgressHighWater, supersetFlowStep, restAfterSet, restOnRecheck, restSecFor, warmupRestSecFor, sideRestFor, stepUnitIndex, advanceAfterTimedRest } from './supersetFlow.js'const entry = done => ({ sets: done.map(value => ({ done: value })) })@@ -237,3 +237,26 @@ describe('stepUnitIndex (#523 skip completed exercises)', () => {})})+describe('advanceAfterTimedRest (#532)', () => {+ const ex = (...done) => ({ sets: done.map(d => ({ done: d })) })+ const timed = set => idx => set.includes(idx)+ it('a finished timed exercise still on screen: the next with work left', () => {+ const entries = [ex(true, true), ex(true), ex(false)]+ expect(advanceAfterTimedRest(entries, [[0], [1], [2]], 0, 0, timed([0]))).toBe(2)+ })+ it('nothing for weighted work, an unfinished one, a screen already moved on, or no work left', () => {+ const entries = [ex(true, true), ex(false)]+ const units = [[0], [1]]+ expect(advanceAfterTimedRest(entries, units, 0, 0, timed([]))).toBeNull()+ expect(advanceAfterTimedRest([ex(true, false), ex(false)], units, 0, 0, timed([0]))).toBeNull()+ expect(advanceAfterTimedRest(entries, units, 0, 1, timed([0]))).toBeNull()+ expect(advanceAfterTimedRest([ex(true), ex(true)], units, 0, 0, timed([0]))).toBeNull()+ expect(advanceAfterTimedRest(entries, units, undefined, 0, timed([0]))).toBeNull()+ })+ it('a superset only when every member is timed and done', () => {+ const entries = [ex(true), ex(true), ex(false)]+ expect(advanceAfterTimedRest(entries, [[0, 1], [2]], 1, 0, timed([0, 1]))).toBe(2)+ expect(advanceAfterTimedRest(entries, [[0, 1], [2]], 1, 0, timed([1]))).toBeNull()+ })+})+diff --git a/frontend/src/views/Workout.jsx b/frontend/src/views/Workout.jsxindex 88354c639..0b8be1e2b 100644--- a/frontend/src/views/Workout.jsx+++ b/frontend/src/views/Workout.jsx@@ -17,7 +17,7 @@ import { pinState } from '../lib/queue.js'import { t, tn, exerciseNameFor, exerciseNameClass } from '../lib/i18n.js'import { api, beacon } from '../lib/api.js'import { pyramidRestFor, maxRecordAt, isPyramid, pyramidLabel } from '../lib/pyramid.js'-import { insertionIndexAfterCurrentUnit, nextUnfinishedUnit, setProgressHighWater, supersetFlowStep, restAfterSet, restOnRecheck, restSecFor, warmupRestSecFor, sideRestFor, stepUnitIndex } from '../lib/supersetFlow.js'+import { insertionIndexAfterCurrentUnit, nextUnfinishedUnit, setProgressHighWater, supersetFlowStep, restAfterSet, restOnRecheck, restSecFor, warmupRestSecFor, sideRestFor, stepUnitIndex, advanceAfterTimedRest } from '../lib/supersetFlow.js'import Media from '../components/Media.jsx'import WorkoutScrollAnchor from '../components/WorkoutScrollAnchor.jsx'import WorkoutChips from '../components/WorkoutChips.jsx'@@ -960,6 +960,17 @@ function ActiveWorkout({ onActionChange }) {const collapseOn = listMode && !!(A.collapseCompleted ?? S.collapseCompleted)// Cards and Focus: Prev, Next and the swipe jump over finished exercises (#523).const skipDone = !listMode && S.skipCompleted === true+ // Cards and Focus: when the rest after a timed exercise's last set runs out, the next exercise+ // comes up on its own (#532, lib/supersetFlow.js advanceAfterTimedRest). Once per rest.+ const readyRest = timer?.ready ? timer : null+ useEffect(() => {+ if (!readyRest || listMode || editing) return+ const live = useStore.getState().S.active+ if (!live) return+ const timed = idx => modeOf({ ...(live.entries[idx]?.target || {}), id: live.entries[idx]?.id }) === 'time'+ const to = advanceAfterTimedRest(live.entries, supersetUnits(live.entries), readyRest.forIdx, live.cur, timed)+ if (to != null) update(s => { if (s.active && s.active.cur === live.cur) s.active.cur = to })+ }, [readyRest?.endsAt])// A finished unit you tapped open again to look at or fix (Discord: "minimize completed exercises// so I view only what I have yet to do"). This screen's own memory: a reload folds it back.// Keyed by index like the units, so a different number of exercises starts over.diff --git a/frontend/src/views/Workout.test.jsx b/frontend/src/views/Workout.test.jsxindex 56917734f..8dab6bfa7 100644--- a/frontend/src/views/Workout.test.jsx+++ b/frontend/src/views/Workout.test.jsx@@ -2880,6 +2880,22 @@ describe('workout controls: the more menu and the set menu', () => {expect(mocks.exerciseHistorySheet).toHaveBeenCalledWith('plain-row')})+ // #532: the rest after a timed exercise's last set runs out, and the next exercise comes up.+ it('after the last hold\'s rest runs out, Cards moves on to the next exercise; weighted work waits', async () => {+ const plank = exercise('plain-plank', [true, true], { target: { mode: 'time', sec: 30 } })+ await mount([plank, exercise('plain-row', [false])], 0)+ mocks.timer = { ready: true, left: 0, forIdx: 0, endsAt: 123 }+ await rerender()+ expect(mocks.S.active.cur).toBe(1)+ await unmount()+ mocks.timer = null+ await mount([exercise('plain-bench', [true, true]), exercise('plain-row', [false])], 0)+ mocks.timer = { ready: true, left: 0, forIdx: 0, endsAt: 124 }+ await rerender()+ expect(mocks.S.active.cur).toBe(0)+ mocks.timer = null+ })+// #523: "Skip completed exercises" makes Next hop over a finished exercise in Cards.it('with skip completed on, Next hops over a finished exercise; off, it steps to it', async () => {const three = () => [exercise('plain-bench', [false]), exercise('plain-row', [true, true]), exercise('plain-curl', [false])]