mirror of
https://github.com/pacnpal/thrilltrack-explorer.git
synced 2025-12-23 02:31:12 -05:00
Refactor: Complete type safety migration
This commit is contained in:
@@ -22,6 +22,7 @@ import { User, MapPin, Calendar, Star, Trophy, Settings, Camera, Edit3, Save, X,
|
||||
import { Profile as ProfileType, ActivityEntry, ReviewActivity, SubmissionActivity, RankingActivity } from '@/types/database';
|
||||
import { supabase } from '@/integrations/supabase/client';
|
||||
import { useToast } from '@/hooks/use-toast';
|
||||
import { getErrorMessage } from '@/lib/errorHandler';
|
||||
import { PhotoUpload } from '@/components/upload/PhotoUpload';
|
||||
import { profileEditSchema } from '@/lib/validation';
|
||||
import { LocationDisplay } from '@/components/profile/LocationDisplay';
|
||||
@@ -109,8 +110,12 @@ export default function Profile() {
|
||||
coasterCount: coasterCount,
|
||||
parkCount: parkCount
|
||||
});
|
||||
} catch (error: any) {
|
||||
} catch (error) {
|
||||
console.error('Error fetching calculated stats:', error);
|
||||
toast({
|
||||
variant: 'destructive',
|
||||
description: getErrorMessage(error),
|
||||
});
|
||||
// Set defaults on error
|
||||
setCalculatedStats({
|
||||
rideCount: 0,
|
||||
@@ -269,8 +274,12 @@ export default function Profile() {
|
||||
.slice(0, 15) as ActivityEntry[];
|
||||
|
||||
setRecentActivity(combined);
|
||||
} catch (error: any) {
|
||||
} catch (error) {
|
||||
console.error('Error fetching recent activity:', error);
|
||||
toast({
|
||||
variant: 'destructive',
|
||||
description: getErrorMessage(error),
|
||||
});
|
||||
setRecentActivity([]);
|
||||
} finally {
|
||||
setActivityLoading(false);
|
||||
@@ -326,12 +335,12 @@ export default function Profile() {
|
||||
await fetchCalculatedStats(data.user_id);
|
||||
await fetchRecentActivity(data.user_id);
|
||||
}
|
||||
} catch (error: any) {
|
||||
} catch (error) {
|
||||
console.error('Error fetching profile:', error);
|
||||
toast({
|
||||
variant: "destructive",
|
||||
title: "Error loading profile",
|
||||
description: error.message
|
||||
description: getErrorMessage(error)
|
||||
});
|
||||
} finally {
|
||||
setLoading(false);
|
||||
@@ -367,12 +376,12 @@ export default function Profile() {
|
||||
await fetchCalculatedStats(user.id);
|
||||
await fetchRecentActivity(user.id);
|
||||
}
|
||||
} catch (error: any) {
|
||||
} catch (error) {
|
||||
console.error('Error fetching profile:', error);
|
||||
toast({
|
||||
variant: "destructive",
|
||||
title: "Error loading profile",
|
||||
description: error.message
|
||||
description: getErrorMessage(error)
|
||||
});
|
||||
} finally {
|
||||
setLoading(false);
|
||||
@@ -440,11 +449,11 @@ export default function Profile() {
|
||||
description: "Your profile has been updated successfully."
|
||||
});
|
||||
}
|
||||
} catch (error: any) {
|
||||
} catch (error) {
|
||||
toast({
|
||||
variant: "destructive",
|
||||
title: "Error updating profile",
|
||||
description: error.message
|
||||
description: getErrorMessage(error)
|
||||
});
|
||||
}
|
||||
};
|
||||
@@ -485,14 +494,14 @@ export default function Profile() {
|
||||
title: "Avatar updated",
|
||||
description: "Your profile picture has been updated successfully."
|
||||
});
|
||||
} catch (error: any) {
|
||||
} catch (error) {
|
||||
// Revert local state on error
|
||||
setAvatarUrl(profile?.avatar_url || '');
|
||||
setAvatarImageId(profile?.avatar_image_id || '');
|
||||
toast({
|
||||
variant: "destructive",
|
||||
title: "Error updating avatar",
|
||||
description: error.message
|
||||
description: getErrorMessage(error)
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user