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.
JavaScript apple-watchbodyweightdockerfitnessfitness-trackergymhealthiosmcpnodejspasskeysprogressive-web-applicationspwareactself-hostedself-hostingvitewebauthnweightliftingworkout-tracker
fix(plates): a load-kind pick made from exercise detail is stored
Boris 'B' Kurktchieva7935eb62fe9
diff --git a/frontend/src/sheets.jsx b/frontend/src/sheets.jsxindex 71020da59..c2cece543 100644--- a/frontend/src/sheets.jsx+++ b/frontend/src/sheets.jsx@@ -682,10 +682,22 @@ function BarWeightEditor({ ex, cfg, extra }) {const noBar = bar && isNoBar(st, ex.id)const def = defaultBarWeight(ex.eq, st.unit)const base = baseWeightFor(st, ex)+ // The kinds a pick would only be restating. With a `cfg` there is one: the same default the+ // rows derive. Without one the equipment decides — and for body-weight equipment that answer+ // ('single', the load being whatever you hang on) is not the one a routine logging the total+ // derives ('none', bodyweight: false), so the segment sits lit on a kind the rows do not use+ // and the pick that would fix it is the only way to say so: both readings are consulted, and+ // it is stored unless it is the default under either. Everything else keeps the plain rule —+ // a dumbbell's cfg-less 'none' is what a dumbbell row derives, and storing it would freeze+ // 'none' onto the exercise everywhere, override the 'single' an added-weight entry derives,+ // and leave no pick that takes the key off again.+ const defaults = cfg ? [loadKindFor(null, ctx)]+ : isBodyweightEq(ex.id) ? [true, false].map(b => loadKindFor(null, { id: ex.id, bodyweight: b }))+ : [loadKindFor(null, ctx)]// Picking what the equipment already implies puts the exercise back on it (a stamped null,// lib/plates.js), so a later change of the equipment's own default still reaches it.const setKind = k => update(s => {- s.loadKind = withLoadKind(s.loadKind, ex.id, k === loadKindFor(null, ctx) ? null : k)+ s.loadKind = withLoadKind(s.loadKind, ex.id, defaults.every(d => d === k) ? null : k)})const setBar = v => update(s => {s.barWeights = s.barWeights || {}diff --git a/frontend/src/sheets.plates.test.jsx b/frontend/src/sheets.plates.test.jsxindex de65767e3..fb9d92695 100644--- a/frontend/src/sheets.plates.test.jsx+++ b/frontend/src/sheets.plates.test.jsx@@ -10,10 +10,12 @@ import { useStore, DEF } from './store/useStore.js'import { useUI } from './store/useUI.js'import { barWeightSheet, plateInventorySheet } from './sheets.jsx'import { EXIDX } from './lib/exercises.js'+import { loadKindFor } from './lib/plates.js'const SQUAT = '0043' // barbellconst COCOONS = '0260' // body weightconst LEG_PRESS = EXIDX['0585'] ? '0585' : Object.values(EXIDX).find(e => e.eq === 'leverage machine').id+const DUMBBELL = Object.values(EXIDX).find(e => e.eq === 'dumbbell').idconst mounted = []function mountTopSheet() {@@ -48,6 +50,7 @@ describe('plate loading editor', () => {expect(EXIDX[SQUAT].eq).toBe('barbell')expect(EXIDX[LEG_PRESS].eq).toBe('leverage machine')expect(EXIDX[COCOONS].eq).toBe('body weight')+ expect(EXIDX[DUMBBELL].eq).toBe('dumbbell')})it('the editor derives its default from the same config the workout rows use', () => {@@ -65,6 +68,38 @@ describe('plate loading editor', () => {expect(segButton(host2, 'Single stack').classList.contains('on')).toBe(true)})+ it('a pick the equipment alone cannot settle is stored, not read back as the default', () => {+ // The exercise-detail sheet has no routine config, so it cannot know whether the routine logs+ // this body-weight exercise as added weight ('single') or as a plain total ('none') — the two+ // readings of the bodyweight flag disagree. The segment shows the body-weight default, and+ // tapping it used to match the cfg-less default and delete the key: the pick stored nothing+ // and the rows of a bodyweight:false routine went on showing no plate line at all.+ act(() => barWeightSheet(COCOONS))+ const host = mountTopSheet()+ expect(segButton(host, 'Single stack').classList.contains('on')).toBe(true)+ act(() => segButton(host, 'Single stack').click())+ expect(S().loadKind[COCOONS]).toEqual(stamped('single'))+ expect(loadKindFor(S(), { id: COCOONS, bodyweight: false })).toBe('single')+ // 'Off' is the other reading's default and is stored just the same.+ act(() => segButton(host, 'Off').click())+ expect(S().loadKind[COCOONS]).toEqual(stamped('none'))+ })++ it('a dumbbell still stores no kind of its own for the one its equipment already implies', () => {+ // The two readings of the bodyweight flag differ for a dumbbell too ('single' as added+ // weight, 'none' as a plain loaded lift), but the cfg-less default — 'none' — is what a+ // dumbbell row derives, so the segment and the rows already agree and the pick is only+ // restating it. Storing it would freeze 'none' onto the exercise everywhere and override the+ // 'single' an entry with bodyweight: true derives, with no way left to take it off: the pick+ // puts the exercise back on its equipment's (a stamped null) instead.+ act(() => barWeightSheet(DUMBBELL))+ const host = mountTopSheet()+ expect(segButton(host, 'Off').classList.contains('on')).toBe(true)+ act(() => segButton(host, 'Off').click())+ expect(S().loadKind[DUMBBELL]).toEqual(stamped(null))+ expect(loadKindFor(S(), { id: DUMBBELL, bodyweight: true })).toBe('single')+ })+it('a barbell defaults to per side and stores nothing until you pick something else', () => {act(() => barWeightSheet(SQUAT))const host = mountTopSheet()