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: block empty progression step saves
Manuel0ab0f4725981
diff --git a/frontend/src/components/ui.jsx b/frontend/src/components/ui.jsxindex 8c9fd0cd5..11fa4ee85 100644--- a/frontend/src/components/ui.jsx+++ b/frontend/src/components/ui.jsx@@ -115,13 +115,13 @@ export function Segmented({ options, value, onChange, className = '' }) {/* ============================ stepper ============================ */-export function Stepper({ value, step = 1, onChange, decimal = true, className = '', label, unit }) {+export function Stepper({ value, step = 1, onChange, decimal = true, className = '', label, unit, invalid = false }) {const set = v => onChange(Math.max(0, Math.round((v || 0) * 100) / 100))const inner = (<div className={'stp ' + className}><button onClick={() => set((+value || 0) - step)} aria-label="Decrease"><Icon name="minus" /></button><span className="val">- <NumberField value={value} decimal={decimal} onChange={onChange} />+ <NumberField value={value} decimal={decimal} onChange={onChange} aria-invalid={invalid ? 'true' : undefined} />{unit && <i>{unit}</i>}</span><button onClick={() => set((+value || 0) + step)} aria-label="Increase"><Icon name="plus" /></button>diff --git a/frontend/src/index.css b/frontend/src/index.cssindex a34845995..6037e687c 100644--- a/frontend/src/index.css+++ b/frontend/src/index.css@@ -526,6 +526,7 @@ h4.sec{-moz-appearance:textfield;appearance:textfield;}.stp .num::-webkit-inner-spin-button{display:none}+.stp.invalid{box-shadow:inset 0 0 0 1px var(--red)}/* --- slider --- */.sld{position:relative;height:32px;display:flex;align-items:center;cursor:pointer;touch-action:none}diff --git a/frontend/src/sheets.jsx b/frontend/src/sheets.jsxindex 0bd5faf42..e0838811f 100644--- a/frontend/src/sheets.jsx+++ b/frontend/src/sheets.jsx@@ -547,12 +547,18 @@ export const equipmentProfileSheet = profile => ui().openSheet(close => <Equipme// Progression settings for one exercise (issue #17). Shown inside the config sheet because// "how does this lift go up" belongs next to sets and reps, not in a separate screen. Left// on "follow the routine" it inherits, so most people never touch it.+const progressionStepOf = (c, mode, ex, unit) =>+ c.inc >= 0 ? c.inc : (mode === 'time' ? 5 : defaultIncrement(ex.id, unit))+const progressionStepIsValid = (step, policy) =>+ policy === 'off' || (Number.isFinite(step) && step > 0)+function ProgressionFields({ ex, mode, c, setC, routine, unit }) {const options = POLICIES_FOR[mode] || ['off']if (options.length < 2) return nullconst inherited = policyFor({ id: ex.id }, routine, mode)const active = policyFor({ ...c, id: ex.id }, routine, mode)- const inc = c.inc >= 0 ? c.inc : (mode === 'time' ? 5 : defaultIncrement(ex.id, unit))+ const inc = progressionStepOf(c, mode, ex, unit)+ const invalid = !progressionStepIsValid(inc, active)return <><h4 className="sec">{t('Progression')}</h4><div className="sect-b" style={{ marginBottom: 8 }}>@@ -563,10 +569,14 @@ function ProgressionFields({ ex, mode, c, setC, routine, unit }) {<div className="small dim" style={{ marginBottom: active === 'off' ? 18 : 10 }}>{t(POLICY_DESC[active])}</div>{active !== 'off' && <div className="row cfgrow" style={{ marginBottom: 18 }}><Stepper label={mode === 'time' ? t('Step (seconds)') : t('Step ({0})', unit)} value={inc}- step={mode === 'time' ? 5 : 1.25} decimal={mode !== 'time'} onChange={v => setC(x => ({ ...x, inc: v }))} />+ step={mode === 'time' ? 5 : 1.25} decimal={mode !== 'time'} invalid={invalid} className={invalid ? 'invalid' : ''}+ onChange={v => setC(x => ({ ...x, inc: v }))} />{active === 'double' && <Stepper label={t('Reps from')} value={c.repsMin || Math.max(1, (c.reps || 10) - 2)}step={1} decimal={false} onChange={v => setC(x => ({ ...x, repsMin: v }))} />}</div>}+ {invalid && <div className="small" role="alert" style={{ color: 'var(--red)', marginTop: -10, marginBottom: 18 }}>+ {t('Enter a positive step to use this progression rule.')}+ </div>}</>}@@ -580,9 +590,12 @@ function ExConfig({ ex, existing, onSave, onDelete, close, routine, initial }) {// Both default from the dataset and are then whatever the config says — see isBw.const bw = !cardio && isBw({ ...c, id: ex.id })const perSide = isPerSide(c)+ const progressionPolicy = policyFor({ ...c, id: ex.id }, routine, mode)+ const progressionStepInvalid = !progressionStepIsValid(progressionStepOf(c, mode, ex, st.unit), progressionPolicy)// Keep whatever the other mode already had (sets, weight) and fill only what is missing.const setMode = m => setC(x => ({ ...defaultConfig(ex.id, m), ...x, mode: m }))const save = () => {+ if (progressionStepInvalid) returnclose()const sets = Math.max(1, Math.round(c.sets) || (cardio ? 1 : 3))// Only carry progression settings that differ from the inherited default, so a plan file@@ -756,7 +769,7 @@ function ExConfig({ ex, existing, onSave, onDelete, close, routine, initial }) {<textarea className="input" rows={3} maxLength={500} style={{ marginBottom: 18 }}placeholder={t('Note (optional) — loading cues, "bar only then +1 plate/side each set", anything worth remembering here')}value={c.note || ''} onChange={e => setC(x => ({ ...x, note: e.target.value }))} />- <Button variant="primary" onClick={save}>{existing ? t('Save') : t('Add to routine')}</Button>+ <Button variant="primary" disabled={progressionStepInvalid} onClick={save}>{existing ? t('Save') : t('Add to routine')}</Button>{ex.custom && <><div style={{ height: 8 }} /><Button icon="pencil" onClick={() => { close(); customExSheet(ex) }}>{t('Edit or delete this exercise')}</Button></>}{onDelete && <><div style={{ height: 8 }} /><Button variant="danger" onClick={() => { close(); onDelete() }}>{t('Remove from routine')}</Button></>}</>diff --git a/frontend/src/sheets.test.jsx b/frontend/src/sheets.test.jsxindex fed2b47e7..9c1b83e4d 100644--- a/frontend/src/sheets.test.jsx+++ b/frontend/src/sheets.test.jsx@@ -51,19 +51,31 @@ describe('exercise configuration progression step', () => {expect(step.value).toBe('0.5')})- it('persists a positive decimal but omits a cleared progression increment', () => {- const positive = renderConfig()- act(() => { type(positive.step, '0,5') })- const positiveSave = [...positive.host.querySelectorAll('button')]+ it('blocks saving without a positive progression step but accepts a positive decimal', () => {+ const config = renderConfig()+ const save = [...config.host.querySelectorAll('button')].find(b => /^(save|add to routine)$/i.test(b.textContent.trim()))- act(() => { positiveSave.click() })- expect(positive.onSave).toHaveBeenCalledWith(expect.objectContaining({ inc: 0.5 }))- const empty = renderConfig()- act(() => { type(empty.step, '') })- const emptySave = [...empty.host.querySelectorAll('button')]- .find(b => /^(save|add to routine)$/i.test(b.textContent.trim()))- act(() => { emptySave.click() })- expect(empty.onSave.mock.calls[0][0]).not.toHaveProperty('inc')+ act(() => { type(config.step, '') })+ expect(config.step.value).toBe('')+ expect(config.step.getAttribute('aria-invalid')).toBe('true')+ expect(save.disabled).toBe(true)+ expect(config.host.textContent).toContain('Enter a positive step to use this progression rule.')++ act(() => { save.click() })+ expect(config.onSave).not.toHaveBeenCalled()+ expect(useUI.getState().sheets).toHaveLength(1)++ act(() => { type(config.step, '0') })+ expect(save.disabled).toBe(true)++ act(() => { type(config.step, '0,5') })+ expect(config.step.value).toBe('0.5')+ expect(config.step.getAttribute('aria-invalid')).not.toBe('true')+ expect(save.disabled).toBe(false)++ act(() => { save.click() })+ expect(config.onSave).toHaveBeenCalledWith(expect.objectContaining({ inc: 0.5 }))+ expect(useUI.getState().sheets).toHaveLength(0)})})