From c08381e558329ece5569a1677edcc8e7fd44e22a Mon Sep 17 00:00:00 2001 From: Duarte Santos Date: Thu, 30 Jul 2026 19:53:14 +0200 Subject: [PATCH] RIR: an unlogged RIR stays unlogged, and the header lines up MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit A set that never had an RIR could still end up carrying one: NumberField mapped an empty field to 0 and the − button clamped to 0, so one stray tap stamped '(RIR 0)' — went to failure — on the set for good, in history and in backups, with no way back. An optional field now clears to null (the key is dropped), and stepping down from empty leaves it empty. A typed 0 still logs a real 0. The row's three-stepper sizing also has to reach the header, or the labels sit up to 5px off the columns they name. --- frontend/src/components/ui.jsx | 9 ++++++--- frontend/src/index.css | 13 +++++++------ frontend/src/lib/history.test.js | 6 ++++++ frontend/src/views/Workout.jsx | 28 +++++++++++++++++++++------- 4 files changed, 40 insertions(+), 16 deletions(-) diff --git a/frontend/src/components/ui.jsx b/frontend/src/components/ui.jsx index 0cd6404..3a1a672 100644 --- a/frontend/src/components/ui.jsx +++ b/frontend/src/components/ui.jsx @@ -21,15 +21,18 @@ import Icon from './Icon.jsx' // Numeric input accepting "," as decimal separator — iOS decimal keypads in many // locales only offer a comma, and type="number" reports "" for it (value snaps to // 0). Keeps a local string draft while focused so partial input like "33," survives. -export function NumberField({ value, onChange, decimal = true, className = '', ...rest }) { +// `nullable` is for fields where "nothing entered" and 0 mean different things (RIR: a +// logged 0 is a set taken to failure). Those clear back to null instead of snapping to 0. +export function NumberField({ value, onChange, decimal = true, nullable = false, className = '', ...rest }) { const [draft, setDraft] = useState(null) const committed = useRef(null) - if (draft !== null && committed.current !== value) { setDraft(null); committed.current = null } + // null and undefined are the same "empty" here — a nullable field's key is dropped once cleared. + if (draft !== null && (committed.current ?? null) !== (value ?? null)) { setDraft(null); committed.current = null } const commit = raw => { let s = raw.replace(/,/g, '.').replace(/[^0-9.]/g, '') const i = s.indexOf('.') if (i !== -1) s = decimal ? s.slice(0, i + 1) + s.slice(i + 1).replace(/\./g, '') : s.slice(0, i) - const n = s === '' || s === '.' ? 0 : Math.max(0, parseFloat(s)) + const n = s === '' || s === '.' ? (nullable ? null : 0) : Math.max(0, parseFloat(s)) committed.current = n setDraft(s) onChange(n) diff --git a/frontend/src/index.css b/frontend/src/index.css index 7cec074..5f74027 100644 --- a/frontend/src/index.css +++ b/frontend/src/index.css @@ -539,7 +539,7 @@ h4.sec{ .sethead .n-sp{width:24px;flex:none} .sethead .w-sp{flex:1.4;text-align:center} .sethead .r-sp{flex:1;text-align:center} -.sethead .rir-sp{flex:1.1;text-align:center} +.sethead .rir-sp{text-align:center} .sethead .ck-sp{width:30px;flex:none} .setrow{display:flex;align-items:center;gap:8px;padding:7px 0;position:relative} .setrow+.setrow::before{ @@ -557,11 +557,12 @@ h4.sec{ /* a 3rd stepper (RIR) needs narrower buttons and a tighter row gap to fit next to weight+reps on narrow phones, same technique as the exercise-config sheet's three-steppers-in-a-row (.cfgrow below) — RIR's own value is short ("1.5") so its buttons shrink the most, weight/reps - just enough to make room since their values ("82.5", "12") need more of what's left. */ -.setrow.rir3{gap:6px} -.setrow.rir3 .stp.w{flex:1.2} -.setrow.rir3 .stp.r{flex:1} -.setrow.rir3 .stp.rir{flex:.85} + just enough to make room since their values ("82.5", "12") need more of what's left. + The header shares the numbers so its labels stay centred over the steppers they name. */ +.setrow.rir3,.sethead.rir3{gap:6px} +.setrow.rir3 .stp.w,.sethead.rir3 .w-sp{flex:1.2} +.setrow.rir3 .stp.r,.sethead.rir3 .r-sp{flex:1} +.setrow.rir3 .stp.rir,.sethead.rir3 .rir-sp{flex:.85} .setrow.rir3 .stp button{width:23px} .setrow.rir3 .stp.rir button{width:20px} .setrow.rir3 .stp .num{font-size:14px} diff --git a/frontend/src/lib/history.test.js b/frontend/src/lib/history.test.js index ec05d9a..77bda11 100644 --- a/frontend/src/lib/history.test.js +++ b/frontend/src/lib/history.test.js @@ -69,6 +69,12 @@ describe('setLabel', () => { expect(setLabel(LIFT, { w: 60, r: 10, rir: 1.5 })).toBe('60×10 (RIR 1.5)') expect(setLabel(LIFT, { w: 60, r: 10, rir: 0 })).toBe('60×10 (RIR 0)') }) + + it('says nothing about RIR on a set that never logged one', () => { + expect(setLabel(LIFT, { w: 60, r: 10 })).toBe('60×10') + // cleared in the UI: the key is dropped, but a null must read the same as absent + expect(setLabel(LIFT, { w: 60, r: 10, rir: null })).toBe('60×10') + }) }) describe('defaultConfig', () => { diff --git a/frontend/src/views/Workout.jsx b/frontend/src/views/Workout.jsx index ba8b19f..892deff 100644 --- a/frontend/src/views/Workout.jsx +++ b/frontend/src/views/Workout.jsx @@ -76,15 +76,24 @@ function ExerciseBlock({ entryIdx, compact, onToggle, onField, onAddSet, onRemov : timed ? { f: 'w', step: 2.5, dec: true, hd: t('Weight ({0})', S.unit) } : { f: 'r', step: 1, dec: false, hd: t('Reps') } // RIR (reps in reserve) only makes sense for weighted rep sets, not cardio/timed holds, - // and is opt-in (Settings) since it adds a third stepper to every row. - const col3 = mode === 'reps' && S.showRir ? { f: 'rir', step: 0.5, dec: true, hd: t('RIR') } : null + // and is opt-in (Settings) since it adds a third stepper to every row. `opt` because an + // unlogged RIR is not the same as RIR 0 — 0 says the set went to failure. + const col3 = mode === 'reps' && S.showRir ? { f: 'rir', step: 0.5, dec: true, opt: true, hd: t('RIR') } : null + // Stepping an optional field that was never filled in stays empty rather than clamping to 0: + // otherwise one stray − on a fresh row stamps "(RIR 0)" on the set for good. Going down from + // 0.5 still reaches a real 0. + const bump = (s, i, col, dir) => { + const cur = s[col.f] + if (col.opt && cur == null && dir < 0) return + onField(i, col.f, Math.max(0, Math.round(((cur || 0) + dir * col.step) * 100) / 100)) + } // Uses the shared stepper markup so a set row picks up the same control styling // as every other +/- field in the app. const cell = (s, i, col, cls) => (
- - onField(i, col.f, v)} /> - + + onField(i, col.f, v)} /> +
) return <> @@ -105,7 +114,8 @@ function ExerciseBlock({ entryIdx, compact, onToggle, onField, onAddSet, onRemov {t(...plan.why)} }
-
{col1.hd}{col2.hd}{col3 && {col3.hd}}{timed && }
+ {/* the header carries the same rir3 sizing as the rows, or the labels drift off their columns */} +
{col1.hd}{col2.hd}{col3 && {col3.hd}}{timed && }
{entry.sets.map((s, i) =>
{i + 1}
{cell(s, i, col1, 'w')} @@ -143,7 +153,11 @@ function ActiveWorkout() { const done = setsDoneActive(A) const mutEntry = (idx, fn) => update(s => { fn(s.active.entries[idx]) }, true) - const setField = (idx, i, field, v) => mutEntry(idx, e => { e.sets[i][field] = v }) + // Clearing an optional field drops the key rather than storing null, so a set only carries + // what was actually logged — in the session, in history and in a backup. + const setField = (idx, i, field, v) => mutEntry(idx, e => { + if (v == null) delete e.sets[i][field]; else e.sets[i][field] = v + }) const modeAt = idx => modeOf({ ...(A.entries[idx].target || {}), id: A.entries[idx].id }) const addSet = idx => mutEntry(idx, e => { const l = e.sets[e.sets.length - 1]