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.

mrbatch: Listenmodus beendet den Workout nicht mehr zu frueh, Progression-Sheet speichert trotz Store-Clone, Progression-aus auch bei Swap/Sheet, Stepper snappt nur auf dem Raster, exWeights erst beim Abschluss

Duarte Santos0cbd32c0f556
diff --git a/frontend/src/lib/progression.js b/frontend/src/lib/progression.js
index 636af3252..48f36cc87 100644
--- a/frontend/src/lib/progression.js
+++ b/frontend/src/lib/progression.js
@@ -87,8 +87,14 @@ export function snapWeight(v, step) {
if (!(step > 0)) return round1(v)
return round1(Math.round(v / step) * step)
}
+// A tap moves by one step. Snapping to the grid keeps the number identical to what progression
+// would prescribe (61.3 → 62.5 with a 1.25 step, not 62.55) — but only when the current value
+// already sits on that grid; from 62.5 with a 5 kg step a tap gives 67.5, not 70.
export function stepWeight(value, step, direction) {
- return Math.max(0, snapWeight((Number(value) || 0) + direction * step, step))
+ const v = Number(value) || 0
+ const onGrid = step > 0 && Math.abs(v - Math.round(v / step) * step) <= 0.1
+ const next = v + direction * step
+ return Math.max(0, onGrid ? snapWeight(next, step) : round1(next))
}
// Back off by DELOAD_FACTOR, landing on something you can actually load. Rounding to the
// nearest step keeps the cut close to the intended 10 %, but on small weights the nearest
diff --git a/frontend/src/sheets.jsx b/frontend/src/sheets.jsx
index 3b698b1ca..3b3af2edb 100644
--- a/frontend/src/sheets.jsx
+++ b/frontend/src/sheets.jsx
@@ -851,7 +851,7 @@ export function swapActiveWorkoutExercise(index) {
const freestyle = !st.active?.routineId
const step = defaultIncrement(ex.id, st.unit)
const plan = freestyle ? null : nextPrescription(st, full, st.routines.find(r => r.id === st.active.routineId))
- const built = buildSets(st, full, { step, ...(freestyle ? { preferLast: true } : {}) })
+ const built = buildSets(st, full, { step, ...(freestyle ? { preferLast: true } : {}), ...(plan?.kind === 'off' ? { useTarget: true } : {}) })
const replacement = {
id: ex.id,
target: { ...cfg },
diff --git a/frontend/src/views/Workout.jsx b/frontend/src/views/Workout.jsx
index f8bb8d970..3ee32d323 100644
--- a/frontend/src/views/Workout.jsx
+++ b/frontend/src/views/Workout.jsx
@@ -490,13 +490,17 @@ function ActiveWorkout() {
if (!entry) return
const activeId = state.active.id
const entryId = entry.id
+ const entryCount = state.active.entries.length
const routine = state.routines.find(r => r.id === state.active.routineId)
exConfigSheet(exOr(entryId), entry.target, cfg => {
// Store updates clone the state tree. If this exact object is no longer at the captured
// index, the list changed while the sheet was open; an id check alone cannot distinguish
// duplicate occurrences of the same exercise, so fail closed before cloning again.
+ // Every store write clones the tree (the bar-weight stepper inside this very sheet does
+ // one), so object identity is useless here. Same workout, same list length and the same
+ // exercise at the captured index is what "nothing shifted" means.
const current = useStore.getState().S
- if (current.active?.id !== activeId || current.active.entries?.[idx] !== entry) return
+ if (current.active?.id !== activeId || current.active.entries?.length !== entryCount || current.active.entries?.[idx]?.id !== entryId) return
update(s => {
const activeEntry = s.active?.id === activeId ? s.active.entries?.[idx] : null
// The sheet may outlive its workout or entry. Never apply its result to whatever later
@@ -511,7 +515,7 @@ function ActiveWorkout() {
// The sheet edits sets, reps, weight and warm-ups as well as the rule — so the rows are
// rebuilt from the new config the way the session was, and only what you already logged
// is kept in place (done warm-ups first, then done work sets, then the fresh remainder).
- const fresh = applyIntensifierPlan(applyPrescription(buildSets(s, full, { step }), plan, step), full)
+ const fresh = applyIntensifierPlan(applyPrescription(buildSets(s, full, { step, useTarget: plan.kind === 'off' }), plan, step), full)
const doneWarm = activeEntry.sets.filter(x => x.done && isWarmupRow(x))
const doneWork = activeEntry.sets.filter(x => x.done && !isWarmupRow(x))
const freshWarm = fresh.filter(isWarmupRow)
@@ -577,13 +581,17 @@ function ActiveWorkout() {
checked = e.sets[i].done
if (e.sets[i].done) {
beep(S.sound, 1040, 0.12); vibrate(30)
- const unitDone = unit.every(ui => (ui === idx ? e : A.entries[ui]).sets.every(x => x.done))
+ // The unit that owns the ticked set — not the marked one. Since !92 the marker no longer
+ // follows a finished exercise, and in list mode any exercise can be worked on, so judging
+ // the marker's unit here declared the workout complete after one set elsewhere.
+ const ownUnit = unitOf(units, idx)
+ const unitDone = ownUnit.every(ui => (ui === idx ? e : A.entries[ui]).sets.every(x => x.done))
if (unitDone) workoutDone = !nextUnfinishedUnit(A.entries, supersetUnits(A.entries), idx)
if (e.sets.every(x => x.done)) {
exJustDone = true
- const mx = bestWeightForEntry(e)
- e.topW = mx || null
- if (!s.active.backfill && mx > 0) { const cur = s.exWeights[e.id]; if (!cur || mx > cur.w) s.exWeights[e.id] = { w: mx, d: todayISO() } }
+ // topW is captured now; exWeights only at the finish (doFinishWorkout), so a typo you
+ // correct before finishing, or a discarded workout, never becomes the remembered best.
+ e.topW = bestWeightForEntry(e) || null
}
}
}, true)
diff --git a/frontend/src/views/Workout.test.jsx b/frontend/src/views/Workout.test.jsx
index da602753a..ce1a157d9 100644
--- a/frontend/src/views/Workout.test.jsx
+++ b/frontend/src/views/Workout.test.jsx
@@ -219,7 +219,7 @@ describe('Workout set completion flow', () => {
await toggleSet(0)
expect(mocks.S.active.entries[0].topW).toBe(60)
- expect(mocks.S.exWeights['plain-bench'].w).toBe(60)
+ expect(mocks.S.exWeights['plain-bench']).toBeUndefined() // written at the finish, not while ticking
expect(mocks.topWeightSheet).not.toHaveBeenCalled()
expect(mocks.S.active.cur).toBe(0)
expect(mocks.startRest).toHaveBeenCalledWith(90, expect.any(Number))
@@ -903,6 +903,21 @@ describe('workout list view', () => {
expect(mocks.startRest).toHaveBeenCalledWith(90, expect.any(Number))
})
+ it('does not declare the workout complete after a set of a non-current exercise while sets remain', async () => {
+ // The marker stays on the finished bench (!92); ticking the first of three row sets must
+ // not open the completion sheet — the row's own unit still has two sets to go.
+ await mount([
+ exercise('plain-bench', [true], { asked: true }),
+ exercise('plain-row', [false, false, false], { asked: true }),
+ ], 0, { workoutView: 'list' })
+
+ await toggleSet(1)
+
+ expect(mocks.S.active.entries[1].sets[0].done).toBe(true)
+ expect(mocks.workoutCompleteSheet).not.toHaveBeenCalled()
+ expect(mocks.startRest).toHaveBeenCalledWith(90, expect.any(Number))
+ })
+
it('renders a superset as one grouped unit with its own unpair control', async () => {
await mount([
exercise('bench', [false], { sg: 'g1', asked: true }),