mirror of
https://github.com/pacnpal/thrilltrack-explorer.git
synced 2025-12-20 13:51:13 -05:00
Fix: Improve preview loading and error handling
This commit is contained in:
@@ -15,7 +15,25 @@ export function useUnitPreferences() {
|
||||
const [loading, setLoading] = useState(true);
|
||||
|
||||
useEffect(() => {
|
||||
loadPreferences();
|
||||
let mounted = true;
|
||||
|
||||
const load = async () => {
|
||||
try {
|
||||
await loadPreferences();
|
||||
} catch (error) {
|
||||
console.error('Failed to load preferences:', error);
|
||||
} finally {
|
||||
if (mounted) {
|
||||
setLoading(false);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
load();
|
||||
|
||||
return () => {
|
||||
mounted = false;
|
||||
};
|
||||
}, [user]);
|
||||
|
||||
const loadPreferences = async () => {
|
||||
@@ -58,7 +76,15 @@ export function useUnitPreferences() {
|
||||
|
||||
const autoDetectPreferences = useCallback(async () => {
|
||||
try {
|
||||
const response = await supabase.functions.invoke('detect-location');
|
||||
// Add timeout to prevent hanging
|
||||
const timeoutPromise = new Promise((_, reject) =>
|
||||
setTimeout(() => reject(new Error('Location detection timeout')), 5000)
|
||||
);
|
||||
|
||||
const response = await Promise.race([
|
||||
supabase.functions.invoke('detect-location'),
|
||||
timeoutPromise
|
||||
]) as any;
|
||||
|
||||
if (response.data && response.data.measurementSystem) {
|
||||
const newPreferences: UnitPreferences = {
|
||||
|
||||
Reference in New Issue
Block a user