mirror of
https://github.com/pacnpal/thrilltrack-explorer.git
synced 2025-12-21 15:11:12 -05:00
Move to Phase 4-5
This commit is contained in:
@@ -2,20 +2,7 @@ import { useEffect } from 'react';
|
||||
import { useAuth } from '@/hooks/useAuth';
|
||||
import { useUnitPreferences } from '@/hooks/useUnitPreferences';
|
||||
import { logger } from '@/lib/logger';
|
||||
|
||||
function isLocalStorageAvailable(): boolean {
|
||||
try {
|
||||
if (typeof window === 'undefined' || typeof localStorage === 'undefined') {
|
||||
return false;
|
||||
}
|
||||
const testKey = '__localStorage_test__';
|
||||
localStorage.setItem(testKey, 'test');
|
||||
localStorage.removeItem(testKey);
|
||||
return true;
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
import * as storage from '@/lib/localStorage';
|
||||
|
||||
export function useLocationAutoDetect() {
|
||||
const { user } = useAuth();
|
||||
@@ -26,25 +13,21 @@ export function useLocationAutoDetect() {
|
||||
if (loading) return;
|
||||
|
||||
// Check if localStorage is available
|
||||
if (!isLocalStorageAvailable()) {
|
||||
if (!storage.isLocalStorageAvailable()) {
|
||||
logger.warn('localStorage is not available, skipping location auto-detection');
|
||||
return;
|
||||
}
|
||||
|
||||
// Check if we've already attempted detection
|
||||
const hasAttemptedDetection = localStorage.getItem('location_detection_attempted');
|
||||
const hasAttemptedDetection = storage.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(() => {
|
||||
if (isLocalStorageAvailable()) {
|
||||
localStorage.setItem('location_detection_attempted', 'true');
|
||||
}
|
||||
storage.setItem('location_detection_attempted', 'true');
|
||||
}).catch((error) => {
|
||||
console.error('❌ Failed to auto-detect location:', error);
|
||||
if (isLocalStorageAvailable()) {
|
||||
localStorage.setItem('location_detection_attempted', 'true');
|
||||
}
|
||||
logger.error('Failed to auto-detect location', { error });
|
||||
storage.setItem('location_detection_attempted', 'true');
|
||||
});
|
||||
}
|
||||
}, [user, loading, preferences.auto_detect]);
|
||||
|
||||
Reference in New Issue
Block a user