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) => (