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
Rotation: building the loop one routine at a time keeps today's session as done
Duarte Santos77654a4a1660
diff --git a/frontend/src/lib/rotation.js b/frontend/src/lib/rotation.jsindex 0bca1f10a..6a7b11326 100644--- a/frontend/src/lib/rotation.js+++ b/frontend/src/lib/rotation.js@@ -97,8 +97,18 @@ export function saveRotation(s, ids, label, today = todayISO(), now = Date.now()// still resolves that date to a session the queue no longer has (pinState/queue.js).sweepPins(s, (prev?.ids || []).filter(id => !ids.includes(id)), today)// An edit (e.g. removing the last session still to do) can leave the pass complete on the- // spot — without this it would sit idle until a workout happened to reach refillAfter.- if (queueView(s, today)?.complete) startNewPass(s, today, now)+ // spot — without this it would sit idle until a workout happened to reach refillAfter. Only an+ // edit that removed or reordered sessions of a pass that already existed: a pass this save just+ // created or grew is complete only because its sessions were trained already, and those+ // workouts are exactly what it should be showing as done (building the loop one routine at a+ // time after training the first one today). The new pass follows refill semantics: it starts+ // the day after the last workout that credited this one, so nothing already logged re-ticks it.+ if (prev && ids.every(id => prev.ids.includes(id)) && queueView(s, today)?.complete) {+ const q = queueOf(s)+ const last = lastCreditDay(s)+ sweepPins(s, q.ids, today)+ s.queue = newPass(rotationIds(s), label, s.rotation.id, last ? dayAfter(last) : today, sinceAfter(s, q, now))+ }}/**diff --git a/frontend/src/lib/rotation.test.js b/frontend/src/lib/rotation.test.jsindex 60fe6fa75..8a596fe4e 100644--- a/frontend/src/lib/rotation.test.js+++ b/frontend/src/lib/rotation.test.js@@ -91,6 +91,31 @@ describe('editing the sequence', () => {expect(queueRemaining(s)).toEqual(['a'])})+ it('building the loop one routine at a time keeps a session trained today as done', () => {+ // Night QA: Leg Day trained today, then Rotation built as [A], [A,B], [A,B,C]. The first save+ // was complete on the spot, started a strict pass from now, and A read as 'Up next', 0 of 3.+ const s = S({ workouts: [w('a', TODAY)] })+ saveRotation(s, ['a'], 'My split', TODAY, NOW)+ saveRotation(s, ['a', 'b'], 'My split', TODAY, NOW + 1000)+ saveRotation(s, ['a', 'b', 'c'], 'My split', TODAY, NOW + 2000)+ expect(s.queue.strict).toBeUndefined()+ expect(s.queue.startsOn).toBe(TODAY)+ expect(queueView(s, TODAY).items.map(i => i.state)).toEqual(['done', 'next', 'later'])+ })++ it('a removal that completes the pass with today\'s workout starts the next one tomorrow, not strict', () => {+ const s = S({+ rotation: { id: 'r1', sequence: ['a', 'b'], label: 'My split' },+ queue: pass(['a', 'b'], { rotationId: 'r1' }),+ workouts: [w('a', TODAY)],+ })+ saveRotation(s, ['a'], 'My split', TODAY, NOW)+ expect(s.queue.strict).toBeUndefined()+ expect(s.queue.startsOn).toBe('2026-09-13')+ expect(queueView(s, TODAY).waiting).toBe(true)+ expect(queueRemaining(s)).toEqual(['a'])+ })+it('removing a session clears its future pin, but leaves past pins and pins on kept sessions alone', () => {const s = S({rotation: { id: 'r1', sequence: ['a', 'b', 'c'], label: 'My split' },