mirror of
https://github.com/pacnpal/thrilltrack-explorer.git
synced 2025-12-21 18:31:12 -05:00
Fix: Improve preview loading and error handling
This commit is contained in:
@@ -24,27 +24,36 @@ export function useLocationAutoDetect() {
|
||||
// Only run auto-detection after preferences have loaded
|
||||
if (loading) return;
|
||||
|
||||
// Check if localStorage is available
|
||||
if (!isLocalStorageAvailable()) {
|
||||
console.warn('localStorage is not available, skipping location auto-detection');
|
||||
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(() => {
|
||||
if (isLocalStorageAvailable()) {
|
||||
localStorage.setItem('location_detection_attempted', 'true');
|
||||
// Defer auto-detection to not block initial render
|
||||
const timeoutId = setTimeout(() => {
|
||||
try {
|
||||
// Check if localStorage is available
|
||||
if (!isLocalStorageAvailable()) {
|
||||
console.warn('localStorage is not available, skipping location auto-detection');
|
||||
return;
|
||||
}
|
||||
}).catch((error) => {
|
||||
console.error('❌ Failed to auto-detect location:', error);
|
||||
if (isLocalStorageAvailable()) {
|
||||
localStorage.setItem('location_detection_attempted', 'true');
|
||||
|
||||
// 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(() => {
|
||||
if (isLocalStorageAvailable()) {
|
||||
localStorage.setItem('location_detection_attempted', 'true');
|
||||
}
|
||||
}).catch((error) => {
|
||||
console.error('❌ Failed to auto-detect location:', error);
|
||||
if (isLocalStorageAvailable()) {
|
||||
localStorage.setItem('location_detection_attempted', 'true');
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
}, [user, loading, preferences.auto_detect]);
|
||||
} catch (error) {
|
||||
console.error('❌ Error in location auto-detection:', error);
|
||||
}
|
||||
}, 1000); // Defer by 1 second to allow app to render first
|
||||
|
||||
return () => clearTimeout(timeoutId);
|
||||
}, [user, loading, preferences.auto_detect, autoDetectPreferences]);
|
||||
}
|
||||
Reference in New Issue
Block a user