Files
Jean-Luc Makiola 1b0b4d0368 docs(07-01): complete weight unit core plan
- SUMMARY.md with TDD results and 21-test coverage
- STATE.md updated to Plan 2 of 2, 17% progress
- ROADMAP.md marks 07-01 complete (1/2 plans)
- REQUIREMENTS.md marks UNIT-02, UNIT-03 complete

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-16 12:19:10 +01:00

4.0 KiB

phase, plan, subsystem, tags, requires, provides, affects, tech-stack, key-files, key-decisions, patterns-established, requirements-completed, duration, completed
phase plan subsystem tags requires provides affects tech-stack key-files key-decisions patterns-established requirements-completed duration completed
07-weight-unit-selection 01 ui
weight-conversion
formatters
react-hooks
tdd
WeightUnit type export for all weight display components
Parameterized formatWeight(grams, unit) with g/oz/lb/kg support
useWeightUnit() hook wrapping settings API for typed unit access
07-02-PLAN
added patterns
unit-conversion-via-formatters
settings-backed-hooks
created modified
src/client/hooks/useWeightUnit.ts
tests/lib/formatters.test.ts
src/client/lib/formatters.ts
Conversion precision: g=0dp, oz=1dp, lb=2dp, kg=2dp matching common usage
useWeightUnit validates stored value against known units to protect against corrupt data
Weight formatting: always call formatWeight(grams, unit) with WeightUnit parameter
Settings-backed hooks: wrap useSetting with typed validation for domain-specific config
UNIT-02
UNIT-03
2min 2026-03-16

Phase 7 Plan 01: Weight Unit Core Summary

Parameterized formatWeight with g/oz/lb/kg conversion and useWeightUnit settings hook, backed by 21 TDD tests

Performance

  • Duration: 2 min
  • Started: 2026-03-16T11:14:19Z
  • Completed: 2026-03-16T11:16:30Z
  • Tasks: 2
  • Files modified: 3

Accomplishments

  • TDD-developed formatWeight function supporting 4 weight units (g, oz, lb, kg) with appropriate precision
  • WeightUnit type exported for consumption by all display components in Plan 02
  • useWeightUnit convenience hook with validation and "g" default, ready for component integration
  • Full backward compatibility preserved -- formatWeight(grams) still returns "Xg" as before

Task Commits

Each task was committed atomically:

  1. Task 1 (RED): TDD formatWeight tests - 431c179 (test)
  2. Task 1 (GREEN): Implement formatWeight with unit parameter - 6cac0a3 (feat)
  3. Task 2: Create useWeightUnit convenience hook - ada3791 (feat)

TDD task had 2 commits (test -> feat). No refactor needed -- code was already minimal.

Files Created/Modified

  • src/client/lib/formatters.ts - Added WeightUnit type, conversion constants, switch-based unit formatting
  • src/client/hooks/useWeightUnit.ts - Convenience hook wrapping useSetting("weightUnit") with typed validation
  • tests/lib/formatters.test.ts - 21 tests covering all units, null/undefined, backward compat, edge cases

Decisions Made

  • Conversion precision follows common usage: grams rounded (0dp), ounces 1dp, pounds 2dp, kilograms 2dp
  • useWeightUnit validates stored value against a whitelist of known units, protecting against corrupt settings data
  • Conversion constants (GRAMS_PER_OZ=28.3495, GRAMS_PER_LB=453.592, GRAMS_PER_KG=1000) kept as module-level consts, not exported

Deviations from Plan

Auto-fixed Issues

1. [Rule 1 - Bug] Fixed import order in useWeightUnit.ts

  • Found during: Task 2 (useWeightUnit hook creation)
  • Issue: Biome lint required imports sorted alphabetically (type imports before value imports)
  • Fix: Reordered imports to put import type { WeightUnit } before import { useSetting }
  • Files modified: src/client/hooks/useWeightUnit.ts
  • Verification: bun run lint passes clean
  • Committed in: ada3791 (Task 2 commit)

Total deviations: 1 auto-fixed (1 bug - lint order) Impact on plan: Trivial formatting fix. No scope creep.

Issues Encountered

None

User Setup Required

None - no external service configuration required.

Next Phase Readiness

  • WeightUnit type and formatWeight function ready for Plan 02 to wire into all weight-displaying components
  • useWeightUnit hook ready for components to consume the user's preferred unit from settings
  • All 108 existing tests pass (full suite regression check confirmed)

Self-Check: PASSED

All files exist, all commits found, all exports verified.


Phase: 07-weight-unit-selection Completed: 2026-03-16