Self-hosted fitness tracker. Log workouts, track nutrition, and monitor progress. Docker deployment, mobile-friendly.
refactor(steppers): name every stepper increment, not just bodyweight
Cawlumm816ee825c504
diff --git a/mobile/src/components/workouts/GymModeWorkout.tsx b/mobile/src/components/workouts/GymModeWorkout.tsxindex 2020a80..44e3a9a 100644--- a/mobile/src/components/workouts/GymModeWorkout.tsx+++ b/mobile/src/components/workouts/GymModeWorkout.tsx@@ -19,7 +19,7 @@ import { RestTimerBanner } from './RestTimerBanner'import { client, useSettingsStore, useWorkoutSession } from '../../lib/lyftr'import { useWorkoutOutcome } from '../../lib/workoutOutcome'import { useTheme } from '../../theme/useTheme'-import { clampStep, clampValue } from '../../utils/number'+import { PLATE_STEP, REP_STEP, clampStep, clampValue } from '../../utils/number'import { nextIncompleteSet } from '../../utils/workoutSets'import { muscleColor, EQUIPMENT_LABEL } from '../../utils/exerciseUtils'@@ -520,12 +520,12 @@ export function GymModeWorkout() {{/* reps + weight steppers */}<View className="w-full flex-row gap-3"><View className="flex-1">- <StepperTile icon={Repeat} label="Reps" name="reps" step={1} disabled={set.completed} onStep={(d) => updateSet(activeIdx, clampedSetIdx, 'actual_reps', clampStep(set.actual_reps || 0, d, { min: 0 }))}>+ <StepperTile icon={Repeat} label="Reps" name="reps" step={REP_STEP} disabled={set.completed} onStep={(d) => updateSet(activeIdx, clampedSetIdx, 'actual_reps', clampStep(set.actual_reps || 0, d, { min: 0 }))}><NumberField key={`reps-${activeIdx}-${clampedSetIdx}`} inputMode="numeric" value={set.actual_reps ? String(set.actual_reps) : ''} onChange={(v) => updateSet(activeIdx, clampedSetIdx, 'actual_reps', Math.round(clampValue(v)))} placeholder={set.target_reps > 0 ? String(set.target_reps) : '0'} disabled={set.completed} accessibilityLabel="Reps" inputAccessoryViewID={NUMERIC_ACCESSORY_ID} /></StepperTile></View><View className="flex-1">- <StepperTile icon={Dumbbell} label={`Weight (${wUnit})`} name="weight" step={2.5} disabled={set.completed} onStep={(d) => updateSet(activeIdx, clampedSetIdx, 'actual_weight', displayToLbs(clampStep(displayWeight(set.actual_weight, wUnit), d, { min: 0 }), settings.weight_unit))}>+ <StepperTile icon={Dumbbell} label={`Weight (${wUnit})`} name="weight" step={PLATE_STEP} disabled={set.completed} onStep={(d) => updateSet(activeIdx, clampedSetIdx, 'actual_weight', displayToLbs(clampStep(displayWeight(set.actual_weight, wUnit), d, { min: 0 }), settings.weight_unit))}><NumberField key={`wt-${activeIdx}-${clampedSetIdx}`} inputMode="decimal" value={set.actual_weight ? String(displayWeight(set.actual_weight, wUnit)) : ''} onChange={(v) => updateSet(activeIdx, clampedSetIdx, 'actual_weight', displayToLbs(clampValue(v), settings.weight_unit))} placeholder={set.target_weight > 0 ? String(displayWeight(set.target_weight, wUnit)) : '0'} disabled={set.completed} accessibilityLabel="Weight" inputAccessoryViewID={NUMERIC_ACCESSORY_ID} /></StepperTile></View>diff --git a/mobile/src/utils/number.ts b/mobile/src/utils/number.tsindex 2185558..fca103d 100644--- a/mobile/src/utils/number.ts+++ b/mobile/src/utils/number.ts@@ -1,12 +1,35 @@// Port of web/src/utils/number.ts — keep in sync.-// Bodyweight +/- increment. Day-to-day bodyweight moves less than the old 0.5 step-// could express (#80); the field itself accepts 0.1 typed regardless.+// Increments for the +/- stepper buttons, in *display* units — the caller has+// already converted lbs↔kg, so 2.5 means "2.5 of whatever the user is reading".+// They only drive the buttons: every field still accepts any typed value at 0.1+// precision (#39), so a step is a convenience, never a limit.+//+// Three constants rather than one, because each answers a different question about+// the thing being measured:++// How much a body moves between weigh-ins — tenths. The old 0.5 was too coarse to+// express a normal day's change (#80). Used by every bodyweight input: it's+// WeightInput's default step (web) and passed explicitly on the three mobile+// weight screens.export const BODYWEIGHT_STEP = 0.1+// How much a barbell can actually be loaded by — the smallest pair of plates on+// the rack, and the same number in either unit (2.5 lb / 2.5 kg). Used by gym+// mode's weight tile on both platforms. Deliberately NOT the bodyweight step:+// nudging a squat by a tenth of a pound is not a thing you can do.+export const PLATE_STEP = 2.5++// Reps are whole. Used by gym mode's reps tile on both platforms.+export const REP_STEP = 1+// Step a numeric value by `delta`, round to the app's 0.1 precision, and clamp to// [min, max]. Single source for the +/- stepper math shared by WeightInput and the// gym StepperTile (default min 0 also serves as the "no negatives" guard).+//+// The toFixed(1) is what keeps repeated steps exact (183.6 + 0.1 is 183.7, not+// 183.70000000000002) — and it's also the floor on how fine a step can be: 0.1 is+// the smallest one this can express, which is why BODYWEIGHT_STEP stops there.export function clampStep(base: number, delta: number, opts: { min?: number; max?: number } = {}): number {const { min = 0, max = Infinity } = optsconst b = Number.isFinite(base) ? base : 0diff --git a/web/src/components/WeightInput.tsx b/web/src/components/WeightInput.tsxindex 912934b..5fe3355 100644--- a/web/src/components/WeightInput.tsx+++ b/web/src/components/WeightInput.tsx@@ -20,10 +20,15 @@ interface Props {max?: number}-// The field always accepts 0.1 precision (the #39 feature); the +/- buttons step-// by `step`, so gym mode can jump by a plate-sized 2.5 while you can still type an-// exact 0.1 value. Bodyweight takes the default — the smallest step the field can-// hold, since a day's change is often under half a pound (#80).+// Two different granularities that happen to be the same number right now, and must+// not be collapsed into one: INPUT_STEP is what the field accepts typed (the #39+// feature — always tenths, whatever the buttons do), STEP_DEFAULT is how far one+// +/- tap moves. They coincide because bodyweight, the only caller that shows the+// buttons, wants the finest step the field can hold (#80).+//+// Nothing overrides `step` today: the sets tables pass stepper={false}, and gym mode+// builds its own tiles from StepperTile + NumberField (see PLATE_STEP). The prop+// stays for a caller that wants a coarser jump.const INPUT_STEP = 0.1const STEP_DEFAULT = BODYWEIGHT_STEPdiff --git a/web/src/pages/GymModeWorkout.tsx b/web/src/pages/GymModeWorkout.tsxindex 908d08d..acbbaae 100644--- a/web/src/pages/GymModeWorkout.tsx+++ b/web/src/pages/GymModeWorkout.tsx@@ -17,7 +17,7 @@ import { workoutAPI } from '../services/api'import StepperTile from '../components/ui/StepperTile'import NumberField from '../components/ui/NumberField'import DiscardConfirm from '../components/DiscardConfirm'-import { clampStep, clampValue } from '../utils/number'+import { PLATE_STEP, REP_STEP, clampStep, clampValue } from '../utils/number'import { nextIncompleteSet } from '../utils/workoutSets'import { displayWeight, displayToLbs } from '../stores/settings'@@ -611,7 +611,7 @@ export default function GymModeWorkout({ wUnit }: GymModeWorkoutProps) {<div className="w-full grid grid-cols-2 gap-3">{/* Reps — key by set so a half-typed value can't bleed to the next set */}<StepperTile- icon={Repeat} label="Reps" name="reps" step={1} disabled={set.completed}+ icon={Repeat} label="Reps" name="reps" step={REP_STEP} disabled={set.completed}onStep={d => updateSet(activeIdx, clampedSetIdx, 'actual_reps', clampStep(set.actual_reps || 0, d, { min: 0 }))}><NumberField@@ -627,7 +627,7 @@ export default function GymModeWorkout({ wUnit }: GymModeWorkoutProps) {{/* Weight */}<StepperTile- icon={Dumbbell} label={`Weight (${wUnit})`} name="weight" step={2.5} disabled={set.completed}+ icon={Dumbbell} label={`Weight (${wUnit})`} name="weight" step={PLATE_STEP} disabled={set.completed}onStep={d => updateSet(activeIdx, clampedSetIdx, 'actual_weight', displayToLbs(clampStep(displayWeight(set.actual_weight, wUnit), d, { min: 0 }), wUnit))}><NumberFielddiff --git a/web/src/utils/number.ts b/web/src/utils/number.tsindex 16a26e0..5aab5d8 100644--- a/web/src/utils/number.ts+++ b/web/src/utils/number.ts@@ -1,10 +1,33 @@-// Bodyweight +/- increment. Day-to-day bodyweight moves less than the old 0.5 step-// could express (#80); the field itself accepts 0.1 typed regardless.+// Increments for the +/- stepper buttons, in *display* units — the caller has+// already converted lbs↔kg, so 2.5 means "2.5 of whatever the user is reading".+// They only drive the buttons: every field still accepts any typed value at 0.1+// precision (#39), so a step is a convenience, never a limit.+//+// Three constants rather than one, because each answers a different question about+// the thing being measured:++// How much a body moves between weigh-ins — tenths. The old 0.5 was too coarse to+// express a normal day's change (#80). Used by every bodyweight input: it's+// WeightInput's default step (web) and passed explicitly on the three mobile+// weight screens.export const BODYWEIGHT_STEP = 0.1+// How much a barbell can actually be loaded by — the smallest pair of plates on+// the rack, and the same number in either unit (2.5 lb / 2.5 kg). Used by gym+// mode's weight tile on both platforms. Deliberately NOT the bodyweight step:+// nudging a squat by a tenth of a pound is not a thing you can do.+export const PLATE_STEP = 2.5++// Reps are whole. Used by gym mode's reps tile on both platforms.+export const REP_STEP = 1+// Step a numeric value by `delta`, round to the app's 0.1 precision, and clamp to// [min, max]. Single source for the +/- stepper math shared by WeightInput and the// gym StepperTile (default min 0 also serves as the "no negatives" guard).+//+// The toFixed(1) is what keeps repeated steps exact (183.6 + 0.1 is 183.7, not+// 183.70000000000002) — and it's also the floor on how fine a step can be: 0.1 is+// the smallest one this can express, which is why BODYWEIGHT_STEP stops there.export function clampStep(base: number, delta: number, opts: { min?: number; max?: number } = {}): number {const { min = 0, max = Infinity } = optsconst b = Number.isFinite(base) ? base : 0