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.

History: a cardio set whose target carries neither an id nor a mode reads as minutes at a speed again, not 0×0

Duarte Santos188c3f740acd
diff --git a/frontend/src/lib/history.js b/frontend/src/lib/history.js
index 8d0607148..697533555 100644
--- a/frontend/src/lib/history.js
+++ b/frontend/src/lib/history.js
@@ -108,14 +108,16 @@ const effortTail = s => {
// entry or a workout entry); passing an id alone keeps the old body-part behaviour.
// `speedUnit` is the profile's (lib/speed.js speedUnitOf); without one a cardio set reads km/h.
export function setLabel(id, s, cfg, speedUnit) {
- const c = cfg || { id }
+ // The id is the caller's when the config does not carry one: a freestyle target is built
+ // without it, and modeOf would then fall back to 'reps' and print a run as "0×0".
+ const c = cfg ? { ...cfg, id: cfg.id ?? id } : { id }
let mode = modeOf(c)
// A set saved by an older build carries no target with it; the set's own fields still say what
// it was — seconds for a timed set, minutes for cardio — so those are not read back as "0 reps".
if (!cfg && !(s.r > 0)) { if (s.min > 0 || s.speed > 0) mode = 'cardio'; else if (s.sec > 0) mode = 'time' }
if (mode === 'cardio') return `${s.min || 0} min @ ${fmtSpeed(s.speed || 0, speedUnit)}`
if (mode === 'time') return fmtSec(s.sec) + (s.w > 0 ? ` · ${fmtNum(s.w)}` : '')
- const bw = isBw({ ...c, id: c.id ?? id })
+ const bw = isBw(c)
const load = (w, reps) => (bw ? (w > 0 ? `+${fmtNum(w)} × ` : '') + reps : `${fmtNum(w || 0)}×${reps}`)
// A rest-pause set's reps read as its bursts, "60×10+4+2", the way the protocol is written
// down. The row's own `r` is the total either way; a planned set's bursts already add up to it
diff --git a/frontend/src/lib/history.test.js b/frontend/src/lib/history.test.js
index 9b8facdfa..b03bf3f27 100644
--- a/frontend/src/lib/history.test.js
+++ b/frontend/src/lib/history.test.js
@@ -68,6 +68,14 @@ describe('setLabel', () => {
expect(setLabel(CARDIO, {})).toBe('0 min @ 0 km/h')
})
+ // A target built without an id (a freestyle one) and without a mode used to fall back to reps,
+ // so a run read "0×0": the id the caller passes decides the mode then, as it does with no target.
+ it('reads a cardio set by the exercise id when its target carries neither id nor mode', () => {
+ expect(setLabel(CARDIO, { min: 20, speed: 9 }, { sets: 1, min: 20, speed: 8 })).toBe('20 min @ 9 km/h')
+ // a target that says otherwise still wins
+ expect(setLabel(CARDIO, { sec: 45, w: 0 }, { mode: 'time' })).toBe('0:45')
+ })
+
it('appends RIR when present, including a valid 0', () => {
expect(setLabel(LIFT, { w: 60, r: 10, rir: 2 })).toBe('60×10 (RIR 2)')
expect(setLabel(LIFT, { w: 60, r: 10, rir: 1.5 })).toBe('60×10 (RIR 1.5)')