fix: Connect measurement unit preference to backend storage
Fixed measurement unit not persisting across page refreshes: - Settings page now includes measurementUnit in the preferences object when saving - MeasurementUnitSelector now accepts value/onChange props for controlled usage - Settings state properly loads and saves measurementUnit from user preferences - UnitInput component will now correctly read imperial/metric from user.preferences.measurementUnit Previously, measurementUnit was only saved to localStorage but not synced to backend, causing UnitInput to always default to metric since it reads from user.preferences. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -17,6 +17,8 @@ interface MeasurementUnitSelectorProps {
|
||||
variant?: 'standard' | 'outlined' | 'filled';
|
||||
fullWidth?: boolean;
|
||||
showDescription?: boolean;
|
||||
value?: MeasurementSystem;
|
||||
onChange?: (value: MeasurementSystem) => void;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -26,19 +28,25 @@ export function MeasurementUnitSelector({
|
||||
variant = 'outlined',
|
||||
fullWidth = true,
|
||||
showDescription = true,
|
||||
value,
|
||||
onChange,
|
||||
}: MeasurementUnitSelectorProps) {
|
||||
const { measurementSystem, setMeasurementSystem } = useLocale();
|
||||
const { t } = useTranslation('settings');
|
||||
const [selectedSystem, setSelectedSystem] = useState<MeasurementSystem>(measurementSystem);
|
||||
|
||||
useEffect(() => {
|
||||
setSelectedSystem(measurementSystem);
|
||||
}, [measurementSystem]);
|
||||
// Use controlled value if provided, otherwise use hook value
|
||||
const selectedSystem = value !== undefined ? value : measurementSystem;
|
||||
|
||||
const handleSystemChange = (event: SelectChangeEvent) => {
|
||||
const newSystem = event.target.value as MeasurementSystem;
|
||||
setSelectedSystem(newSystem);
|
||||
setMeasurementSystem(newSystem);
|
||||
|
||||
// If onChange is provided (controlled), use it
|
||||
if (onChange) {
|
||||
onChange(newSystem);
|
||||
} else {
|
||||
// Otherwise use the hook (uncontrolled)
|
||||
setMeasurementSystem(newSystem);
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
|
||||
Reference in New Issue
Block a user