diff --git a/src/pages/Profile.tsx b/src/pages/Profile.tsx index a17e4001..d8c41df3 100644 --- a/src/pages/Profile.tsx +++ b/src/pages/Profile.tsx @@ -14,7 +14,7 @@ import { Avatar, AvatarFallback, AvatarImage } from '@/components/ui/avatar'; import { AlertDialog, AlertDialogAction, AlertDialogCancel, AlertDialogContent, AlertDialogDescription, AlertDialogFooter, AlertDialogHeader, AlertDialogTitle, AlertDialogTrigger } from '@/components/ui/alert-dialog'; import { useAuth } from '@/hooks/useAuth'; import { useUsernameValidation } from '@/hooks/useUsernameValidation'; -import { User, MapPin, Calendar, Star, Trophy, Settings, Camera, Edit3, Save, X, ArrowLeft, Check, AlertCircle, Loader2, UserX } from 'lucide-react'; +import { User, MapPin, Calendar, Star, Trophy, Settings, Camera, Edit3, Save, X, ArrowLeft, Check, AlertCircle, Loader2, UserX, FileText, Image } from 'lucide-react'; import { Profile as ProfileType } from '@/types/database'; import { supabase } from '@/integrations/supabase/client'; import { useToast } from '@/hooks/use-toast'; @@ -119,14 +119,21 @@ export default function Profile() { const fetchRecentActivity = async (userId: string) => { setActivityLoading(true); try { + const isOwnProfile = currentUser && currentUser.id === userId; + // Fetch last 10 reviews - const { data: reviews, error: reviewsError } = await supabase + let reviewsQuery = supabase .from('reviews') .select('id, rating, title, created_at, moderation_status, park_id, ride_id, parks(name, slug), rides(name, slug, parks(name, slug))') .eq('user_id', userId) .order('created_at', { ascending: false }) .limit(10); + + if (!isOwnProfile) { + reviewsQuery = reviewsQuery.eq('moderation_status', 'approved'); + } + const { data: reviews, error: reviewsError } = await reviewsQuery; if (reviewsError) throw reviewsError; // Fetch last 10 ride credits @@ -139,10 +146,38 @@ export default function Profile() { if (creditsError) throw creditsError; + // Fetch last 10 submissions + let submissionsQuery = supabase + .from('content_submissions') + .select('id, submission_type, content, status, created_at') + .eq('user_id', userId) + .order('created_at', { ascending: false }) + .limit(10); + + if (!isOwnProfile) { + submissionsQuery = submissionsQuery.eq('status', 'approved'); + } + + const { data: submissions, error: submissionsError } = await submissionsQuery; + if (submissionsError) throw submissionsError; + + // Fetch last 10 rankings (public top lists) + const { data: rankings, error: rankingsError } = await supabase + .from('user_top_lists') + .select('id, title, description, list_type, created_at') + .eq('user_id', userId) + .eq('is_public', true) + .order('created_at', { ascending: false }) + .limit(10); + + if (rankingsError) throw rankingsError; + // Combine and sort by date const combined = [ ...(reviews?.map(r => ({ ...r, type: 'review' })) || []), - ...(credits?.map(c => ({ ...c, type: 'credit' })) || []) + ...(credits?.map(c => ({ ...c, type: 'credit' })) || []), + ...(submissions?.map(s => ({ ...s, type: 'submission' })) || []), + ...(rankings?.map(r => ({ ...r, type: 'ranking' })) || []) ].sort((a, b) => new Date(b.created_at).getTime() - new Date(a.created_at).getTime()) .slice(0, 15); @@ -602,6 +637,14 @@ export default function Profile() {
{activity.type === 'review' ? ( + ) : activity.type === 'credit' ? ( + + ) : activity.type === 'submission' ? ( + activity.submission_type === 'photo' ? ( + + ) : ( + + ) ) : ( )} @@ -641,6 +684,43 @@ export default function Profile() {
) : null} + ) : activity.type === 'submission' ? ( + <> +
+

+ Submitted {activity.submission_type} + {activity.content?.name && `: ${activity.content.name}`} +

+ {activity.status === 'pending' && ( + Pending + )} + {activity.status === 'approved' && ( + Approved + )} + {activity.status === 'rejected' && ( + Rejected + )} +
+ {activity.content?.description && ( +

+ {activity.content.description} +

+ )} + + ) : activity.type === 'ranking' ? ( + <> +
+

Created ranking: {activity.title}

+ + {activity.list_type.replace('_', ' ')} + +
+ {activity.description && ( +

+ {activity.description} +

+ )} + ) : ( <>

Added ride credit