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.

RIR: an unlogged RIR stays unlogged, and the header lines up

Duarte Santosc08381e55832
diff --git a/frontend/src/components/ui.jsx b/frontend/src/components/ui.jsx
index 0cd6404b9..3a1a6721b 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 7cec07448..5f740276a 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 ec05d9a0a..77bda11d2 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 ba8b19f50..892deffe4 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) => (
<div className={'stp ' + cls}>
- <button aria-label="Decrease" onClick={() => onField(i, col.f, Math.max(0, Math.round(((s[col.f] || 0) - col.step) * 100) / 100))}><Icon name="minus" /></button>
- <span className="val"><NumberField decimal={col.dec} value={s[col.f] ?? ''} onChange={v => onField(i, col.f, v)} /></span>
- <button aria-label="Increase" onClick={() => onField(i, col.f, Math.max(0, Math.round(((s[col.f] || 0) + col.step) * 100) / 100))}><Icon name="plus" /></button>
+ <button aria-label="Decrease" onClick={() => bump(s, i, col, -1)}><Icon name="minus" /></button>
+ <span className="val"><NumberField decimal={col.dec} nullable={col.opt} value={s[col.f] ?? ''} onChange={v => onField(i, col.f, v)} /></span>
+ <button aria-label="Increase" onClick={() => bump(s, i, col, 1)}><Icon name="plus" /></button>
</div>
)
return <>
@@ -105,7 +114,8 @@ function ExerciseBlock({ entryIdx, compact, onToggle, onField, onAddSet, onRemov
<span>{t(...plan.why)}</span>
</div>}
<div className="card" style={{ marginTop: 10, marginBottom: 0 }}>
- <div className="sethead"><span className="n-sp" /><span className="w-sp">{col1.hd}</span><span className="r-sp">{col2.hd}</span>{col3 && <span className="rir-sp">{col3.hd}</span>}{timed && <span className="ck-sp" />}<span className="ck-sp" /></div>
+ {/* the header carries the same rir3 sizing as the rows, or the labels drift off their columns */}
+ <div className={'sethead' + (col3 ? ' rir3' : '')}><span className="n-sp" /><span className="w-sp">{col1.hd}</span><span className="r-sp">{col2.hd}</span>{col3 && <span className="rir-sp">{col3.hd}</span>}{timed && <span className="ck-sp" />}<span className="ck-sp" /></div>
{entry.sets.map((s, i) => <div key={i} className={'setrow' + (s.done ? ' done' : '') + (col3 ? ' rir3' : '')}>
<div className="n">{i + 1}</div>
{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]