Self-hosted fitness tracker. Log workouts, track nutrition, and monitor progress. Docker deployment, mobile-friendly.
feat(weight): step bodyweight +/- by 0.1 instead of 0.5 (#80)
Cawlummb8bae3f1e616
diff --git a/mobile/app/(tabs)/weight/[id].tsx b/mobile/app/(tabs)/weight/[id].tsxindex f396e0e..e55d498 100644--- a/mobile/app/(tabs)/weight/[id].tsx+++ b/mobile/app/(tabs)/weight/[id].tsx@@ -13,7 +13,7 @@ import {NumericKeyboardAccessory, NUMERIC_ACCESSORY_ID, Screen, StepperTile, deleteConfirmProps,} from '../../../src/components/ui'import { client, useSettingsStore } from '../../../src/lib/lyftr'-import { clampStep } from '../../../src/utils/number'+import { BODYWEIGHT_STEP, clampStep } from '../../../src/utils/number'import { useTheme } from '../../../src/theme/useTheme'export default function WeightDetail() {@@ -204,7 +204,7 @@ export default function WeightDetail() {icon={Scale}label={`Weight (${wUnit})`}name="weight"- step={0.5}+ step={BODYWEIGHT_STEP}onStep={(d) => setEditWeight(String(clampStep(parseFloat(editWeight) || 0, d, { min: 0, max: maxWeight(unit) })))}><NumberFielddiff --git a/mobile/app/(tabs)/weight/index.tsx b/mobile/app/(tabs)/weight/index.tsxindex 30afc35..cae8cf5 100644--- a/mobile/app/(tabs)/weight/index.tsx+++ b/mobile/app/(tabs)/weight/index.tsx@@ -20,7 +20,7 @@ import { WeightEntryRow } from '../../../src/components/weight/WeightEntryRow'import { WeightSkeleton } from '../../../src/components/weight/WeightSkeleton'import { useServerInfiniteList } from '../../../src/hooks/useServerInfiniteList'import { client, useSettingsStore } from '../../../src/lib/lyftr'-import { clampStep } from '../../../src/utils/number'+import { BODYWEIGHT_STEP, clampStep } from '../../../src/utils/number'import { useTheme } from '../../../src/theme/useTheme'const PERIODS = ['7d', '30d', '90d', 'All'] as const@@ -250,7 +250,7 @@ export default function Weight() {icon={Scale}label={`Weight (${wUnit})`}name="weight"- step={0.5}+ step={BODYWEIGHT_STEP}onStep={(d) => setNewWeight(String(clampStep(parseFloat(newWeight) || 0, d, { min: 0, max: maxWeight(unit) })))}><NumberFielddiff --git a/mobile/src/components/dashboard/QuickWeighInSheet.tsx b/mobile/src/components/dashboard/QuickWeighInSheet.tsxindex 61a28cb..2c3c4a3 100644--- a/mobile/src/components/dashboard/QuickWeighInSheet.tsx+++ b/mobile/src/components/dashboard/QuickWeighInSheet.tsx@@ -11,7 +11,7 @@ import {Sheet, StepperTile,} from '../ui'import { client, useSettingsStore } from '../../lib/lyftr'-import { clampStep } from '../../utils/number'+import { BODYWEIGHT_STEP, clampStep } from '../../utils/number'import { useTheme } from '../../theme/useTheme'interface Props {@@ -134,7 +134,7 @@ export function QuickWeighInSheet({ open, lastValue, lastLog, onClose, onSuccessicon={Scale}label={`Weight (${wUnit})`}name="weight"- step={0.5}+ step={BODYWEIGHT_STEP}onStep={(d) => setValue(String(clampStep(parseFloat(value) || 0, d, { min: 0, max: maxWeight(unit) })))}><NumberFielddiff --git a/mobile/src/utils/number.ts b/mobile/src/utils/number.tsindex 2eac5dd..2185558 100644--- a/mobile/src/utils/number.ts+++ b/mobile/src/utils/number.ts@@ -1,5 +1,9 @@// 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.+export const BODYWEIGHT_STEP = 0.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).diff --git a/web/src/components/WeightInput.test.tsx b/web/src/components/WeightInput.test.tsxindex 5592e50..9e2e6c0 100644--- a/web/src/components/WeightInput.test.tsx+++ b/web/src/components/WeightInput.test.tsx@@ -42,11 +42,20 @@ describe('WeightInput', () => {expect(screen.getByText('kg')).toBeTruthy()})- it('default + button steps by 0.5 (locks STEP_DEFAULT — bodyweight ergonomics)', () => {+ it('default + button steps by 0.1 (locks STEP_DEFAULT — bodyweight moves in tenths)', () => {const onChange = vi.fn()render(<WeightInput value="100" onChange={onChange} unit="lbs" />) // no step propfireEvent.click(screen.getByLabelText(/increase/i))- expect(onChange).toHaveBeenCalledWith('100.5')+ expect(onChange).toHaveBeenCalledWith('100.1')+ })++ it('repeated default steps stay exact — no float dust', () => {+ const onChange = vi.fn()+ render(<WeightInput value="183.6" onChange={onChange} unit="lbs" />)+ fireEvent.click(screen.getByLabelText(/increase/i))+ expect(onChange).toHaveBeenCalledWith('183.7')+ fireEvent.click(screen.getByLabelText(/decrease/i))+ expect(onChange).toHaveBeenLastCalledWith('183.6')})it('the field always accepts 0.1 precision regardless of the button step', () => {diff --git a/web/src/components/WeightInput.tsx b/web/src/components/WeightInput.tsxindex 76d921e..912934b 100644--- a/web/src/components/WeightInput.tsx+++ b/web/src/components/WeightInput.tsx@@ -1,6 +1,6 @@import { Minus, Plus } from 'lucide-react'import { useNumericText } from '../hooks/useNumericText'-import { clampStep } from '../utils/number'+import { BODYWEIGHT_STEP, clampStep } from '../utils/number'interface Props {value: string@@ -21,10 +21,11 @@ interface Props {}// The field always accepts 0.1 precision (the #39 feature); the +/- buttons step-// by `step` — a larger, ergonomic increment — so gym mode can jump by 2.5 while you-// can still type an exact 0.1 value. Bodyweight keeps the original 0.5 button feel.+// 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).const INPUT_STEP = 0.1-const STEP_DEFAULT = 0.5+const STEP_DEFAULT = BODYWEIGHT_STEP// Single component for every weight input in the app. Conversion-agnostic: the// caller owns lbs↔display unit (pass display-unit strings in/out). `stepper`diff --git a/web/src/utils/number.ts b/web/src/utils/number.tsindex 5666bf5..16a26e0 100644--- a/web/src/utils/number.ts+++ b/web/src/utils/number.ts@@ -1,3 +1,7 @@+// 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.+export const BODYWEIGHT_STEP = 0.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).