diff --git a/frontend/src/components/ui.jsx b/frontend/src/components/ui.jsx index 8c9fd0c..11fa4ee 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 = (
- + {unit && {unit}} diff --git a/frontend/src/index.css b/frontend/src/index.css index a348459..6037e68 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.jsx index 0bd5faf..e083881 100644 --- a/frontend/src/sheets.jsx +++ b/frontend/src/sheets.jsx @@ -547,12 +547,18 @@ export const equipmentProfileSheet = profile => ui().openSheet(close => + 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 null const 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 <>

{t('Progression')}

@@ -563,10 +569,14 @@ function ProgressionFields({ ex, mode, c, setC, routine, unit }) {
{t(POLICY_DESC[active])}
{active !== 'off' &&
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' && setC(x => ({ ...x, repsMin: v }))} />}
} + {invalid &&
+ {t('Enter a positive step to use this progression rule.')} +
} } @@ -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) return close() 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 }) {