mirror of
https://github.com/pacnpal/thrilltrack-explorer.git
synced 2025-12-21 16:51:13 -05:00
Fix: Imperial units not displaying
This commit is contained in:
@@ -4,22 +4,35 @@ import { useUnitPreferences } from '@/hooks/useUnitPreferences';
|
||||
|
||||
export function useLocationAutoDetect() {
|
||||
const { user } = useAuth();
|
||||
const { preferences, autoDetectPreferences } = useUnitPreferences();
|
||||
const { preferences, autoDetectPreferences, loading } = useUnitPreferences();
|
||||
|
||||
useEffect(() => {
|
||||
// Only auto-detect if user has auto_detect enabled and we haven't detected yet
|
||||
if (preferences.auto_detect && preferences.measurement_system === 'metric') {
|
||||
// Check if we've already attempted detection
|
||||
const hasAttemptedDetection = localStorage.getItem('location_detection_attempted');
|
||||
|
||||
if (!hasAttemptedDetection) {
|
||||
autoDetectPreferences().then(() => {
|
||||
localStorage.setItem('location_detection_attempted', 'true');
|
||||
}).catch((error) => {
|
||||
console.error('Failed to auto-detect location:', error);
|
||||
localStorage.setItem('location_detection_attempted', 'true');
|
||||
});
|
||||
}
|
||||
// Only run auto-detection after preferences have loaded
|
||||
if (loading) return;
|
||||
|
||||
console.log('🌍 useLocationAutoDetect running:', {
|
||||
user: !!user,
|
||||
preferences,
|
||||
loading
|
||||
});
|
||||
|
||||
// For debugging - clear the flag to test detection again
|
||||
localStorage.removeItem('location_detection_attempted');
|
||||
|
||||
// Check if we've already attempted detection
|
||||
const hasAttemptedDetection = localStorage.getItem('location_detection_attempted');
|
||||
console.log('🔍 Detection attempt status:', hasAttemptedDetection);
|
||||
|
||||
// Auto-detect if we haven't attempted it yet and auto_detect is enabled
|
||||
if (preferences.auto_detect && !hasAttemptedDetection) {
|
||||
console.log('🚀 Starting auto-detection...');
|
||||
autoDetectPreferences().then((result) => {
|
||||
console.log('✅ Auto-detection completed:', result);
|
||||
localStorage.setItem('location_detection_attempted', 'true');
|
||||
}).catch((error) => {
|
||||
console.error('❌ Failed to auto-detect location:', error);
|
||||
localStorage.setItem('location_detection_attempted', 'true');
|
||||
});
|
||||
}
|
||||
}, [user, preferences.auto_detect, preferences.measurement_system, autoDetectPreferences]);
|
||||
}, [user, preferences, loading, autoDetectPreferences]);
|
||||
}
|
||||
Reference in New Issue
Block a user