diff --git a/frontend/src/lib/progression.js b/frontend/src/lib/progression.js index 4cc5547..593e73c 100644 --- a/frontend/src/lib/progression.js +++ b/frontend/src/lib/progression.js @@ -81,18 +81,22 @@ export function policyFor(cfg, routine, mode) { } const round1 = v => Math.round(v * 10) / 10 -// Snap to a loadable multiple of the step. -function snap(v, step) { +// Snap to a loadable multiple of the step. Manual weight controls use this same normalization +// so fractional increments produce the same number as automatic progression. +export function snapWeight(v, step) { if (!(step > 0)) return round1(v) return round1(Math.round(v / step) * step) } +export function stepWeight(value, step, direction) { + return Math.max(0, snapWeight((Number(value) || 0) + direction * step, step)) +} // 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 // step can be the weight you started from — so a deload that did not actually reduce // anything takes one step down instead. Never goes below a single step. function deloadTo(cur, step) { - let next = snap(cur * DELOAD_FACTOR, step) - if (next >= cur) next = snap(cur - step, step) + let next = snapWeight(cur * DELOAD_FACTOR, step) + if (next >= cur) next = snapWeight(cur - step, step) return Math.max(step, next) } @@ -225,7 +229,7 @@ export function nextPrescription(S, cfg, routine) { const range = normalizeRepRange(cfg.reps || last.goal || 10, cfg.repsMin, repStep(cfg)) const top = range.reps const bottom = range.repsMin - if (last.ok) return { policy, kind: 'up', weight: snap(w + inc, inc), reps: bottom, why: ['Top of the rep range in every set — {0} {1} more, back to {2} reps.', inc, unit, bottom] } + if (last.ok) return { policy, kind: 'up', weight: snapWeight(w + inc, inc), reps: bottom, why: ['Top of the rep range in every set — {0} {1} more, back to {2} reps.', inc, unit, bottom] } if (stalls >= deloadAt) { const dw = deloadTo(w, inc) return { policy, kind: 'deload', weight: dw, reps: bottom, why: ['Stalled {0} sessions — deload to {1} {2}.', stalls, dw, unit] } @@ -241,7 +245,7 @@ export function nextPrescription(S, cfg, routine) { const dbl = policy === 'greyskull' && last.goal > 0 && last.amrap >= last.goal * 2 const step = dbl ? inc * 2 : inc return { - policy, kind: 'up', weight: snap(w + step, inc), + policy, kind: 'up', weight: snapWeight(w + step, inc), why: dbl ? ['Last set hit {0} reps — twice the target, so take a double jump of {1} {2}.', last.amrap, step, unit] : ['Every rep last time — {0} {1} more.', step, unit] diff --git a/frontend/src/views/Workout.jsx b/frontend/src/views/Workout.jsx index 367f6bc..e571a42 100644 --- a/frontend/src/views/Workout.jsx +++ b/frontend/src/views/Workout.jsx @@ -13,7 +13,7 @@ import Media from '../components/Media.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, weightIncrement } from '../lib/progression.js' +import { nextPrescription, applyPrescription, defaultIncrement, weightIncrement, stepWeight } from '../lib/progression.js' import { progressionGuidance } from '../lib/progression-copy.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' @@ -140,6 +140,7 @@ function ExerciseBlock({ entryIdx, compact, onToggle, onField, onAddSet, onRemov // with no ceiling, as they always did. const bump = (s, i, col, dir) => { if (col.eff) return onField(i, col.f, stepEffort(col.eff, s[col.f], dir)) + if (mode === 'reps' && col.f === 'w') return onField(i, col.f, stepWeight(s[col.f], col.step, dir)) onField(i, col.f, Math.max(0, Math.round(((s[col.f] || 0) + dir * col.step) * 100) / 100)) } // Uses the shared stepper markup so a set row picks up the same control styling @@ -155,11 +156,11 @@ function ExerciseBlock({ entryIdx, compact, onToggle, onField, onAddSet, onRemov ) // A smaller stepper for a drop's weight/reps or a burst's reps — editing what the plan (or a // live "+ Drop"/"+ Burst" tap) already put on the row, not typing into a fresh field. - const miniStepper = (value, step, dec, onChange) => ( + const miniStepper = (value, step, dec, onChange, snapWeightStep = false) => (