mirror of
https://github.com/pacnpal/thrilltrack-explorer.git
synced 2025-12-23 06:31:12 -05:00
Fix unit preferences logic
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import { useMemo } from 'react';
|
||||
import { useAuth } from '@/hooks/useAuth';
|
||||
import { useUnitPreferences } from '@/hooks/useUnitPreferences';
|
||||
import {
|
||||
convertSpeed,
|
||||
convertDistance,
|
||||
@@ -8,8 +8,7 @@ import {
|
||||
getDistanceUnit,
|
||||
getHeightUnit,
|
||||
getShortDistanceUnit,
|
||||
type MeasurementSystem,
|
||||
type UnitPreferences
|
||||
type MeasurementSystem
|
||||
} from '@/lib/units';
|
||||
|
||||
interface MeasurementDisplayProps {
|
||||
@@ -25,27 +24,7 @@ export function MeasurementDisplay({
|
||||
showBothUnits = false,
|
||||
className = ""
|
||||
}: MeasurementDisplayProps) {
|
||||
const { profile } = useAuth();
|
||||
|
||||
const unitPreferences = useMemo(() => {
|
||||
// Get unit preferences from user profile or default to metric
|
||||
const defaultPrefs: UnitPreferences = {
|
||||
measurement_system: 'metric',
|
||||
temperature: 'celsius',
|
||||
auto_detect: true
|
||||
};
|
||||
|
||||
// If no profile or no preferences, use default
|
||||
if (!profile) return defaultPrefs;
|
||||
|
||||
// Try to get preferences from profile (this will be populated from user_preferences)
|
||||
const storedPrefs = (profile as any)?.unit_preferences;
|
||||
if (storedPrefs && typeof storedPrefs === 'object') {
|
||||
return { ...defaultPrefs, ...storedPrefs };
|
||||
}
|
||||
|
||||
return defaultPrefs;
|
||||
}, [profile]);
|
||||
const { preferences: unitPreferences } = useUnitPreferences();
|
||||
|
||||
const { displayValue, unit, alternateDisplay, tooltipText } = useMemo(() => {
|
||||
const system = unitPreferences.measurement_system;
|
||||
|
||||
Reference in New Issue
Block a user