Files
thrilltrack-explorer/src/hooks/useLocationAutoDetect.ts
gpt-engineer-app[bot] 8f33b36750 Fix unit preferences logic
2025-09-28 23:10:18 +00:00

26 lines
1.0 KiB
TypeScript

import { useEffect } from 'react';
import { useAuth } from '@/hooks/useAuth';
import { useUnitPreferences } from '@/hooks/useUnitPreferences';
export function useLocationAutoDetect() {
const { user } = useAuth();
const { preferences, autoDetectPreferences, loading } = useUnitPreferences();
useEffect(() => {
// Only run auto-detection after preferences have loaded
if (loading) return;
// Check if we've already attempted detection
const hasAttemptedDetection = localStorage.getItem('location_detection_attempted');
// Auto-detect if we haven't attempted it yet and auto_detect is enabled
if (preferences.auto_detect && !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');
});
}
}, [user, loading, preferences.auto_detect]);
}