From 9866b87f7f33ecb130c091b3272a0bbe53e1b348 Mon Sep 17 00:00:00 2001 From: "gpt-engineer-app[bot]" <159125892+gpt-engineer-app[bot]@users.noreply.github.com> Date: Thu, 9 Oct 2025 16:46:39 +0000 Subject: [PATCH] feat: Add detailed logging to PhotoSubmissionDisplay --- .../moderation/PhotoSubmissionDisplay.tsx | 67 +++++++++++++++++-- 1 file changed, 61 insertions(+), 6 deletions(-) diff --git a/src/components/moderation/PhotoSubmissionDisplay.tsx b/src/components/moderation/PhotoSubmissionDisplay.tsx index 1e7b32d1..3b002d3d 100644 --- a/src/components/moderation/PhotoSubmissionDisplay.tsx +++ b/src/components/moderation/PhotoSubmissionDisplay.tsx @@ -11,41 +11,80 @@ export function PhotoSubmissionDisplay({ submissionId }: PhotoSubmissionDisplayP const isMobile = useIsMobile(); const [photos, setPhotos] = useState([]); const [loading, setLoading] = useState(true); + const [error, setError] = useState(null); useEffect(() => { fetchPhotos(); }, [submissionId]); const fetchPhotos = async () => { + console.log('🖼️ PhotoSubmissionDisplay: Starting fetch for submission:', submissionId); + try { + // Check user auth and roles + const { data: session } = await supabase.auth.getSession(); + const userId = session?.session?.user?.id; + console.log('👤 Current user ID:', userId); + + if (userId) { + const { data: roles } = await supabase + .from('user_roles') + .select('role') + .eq('user_id', userId); + console.log('👤 Current user roles:', roles); + } + // Step 1: Get photo_submission_id from submission_id + console.log('📸 Step 1: Querying photo_submissions table...'); const { data: photoSubmission, error: photoSubmissionError } = await supabase .from('photo_submissions') - .select('id') + .select('id, entity_type, title') .eq('submission_id', submissionId) .maybeSingle(); - if (photoSubmissionError) throw photoSubmissionError; + console.log('📸 Photo submission query result:', { + photoSubmission, + error: photoSubmissionError + }); + + if (photoSubmissionError) { + console.error('❌ Error fetching photo_submission:', photoSubmissionError); + throw photoSubmissionError; + } if (!photoSubmission) { + console.log('⚠️ No photo_submission found for submission_id:', submissionId); setPhotos([]); setLoading(false); return; } + console.log('✅ Found photo_submission ID:', photoSubmission.id); + // Step 2: Get photo items using photo_submission_id + console.log('🖼️ Step 2: Querying photo_submission_items table...'); const { data, error } = await supabase .from('photo_submission_items') .select('*') .eq('photo_submission_id', photoSubmission.id) .order('order_index'); - if (error) throw error; + console.log('🖼️ Photo items query result:', { + itemCount: data?.length, + error + }); + + if (error) { + console.error('❌ Error fetching photo_submission_items:', error); + throw error; + } setPhotos(data || []); - } catch (error) { - console.error('Error fetching photo submission items:', error); + console.log(`✅ Successfully loaded ${data?.length || 0} photos`); + } catch (error: any) { + console.error('❌ PhotoSubmissionDisplay error:', error); setPhotos([]); + setError(error.message || 'Failed to load photos'); } finally { setLoading(false); } @@ -55,8 +94,24 @@ export function PhotoSubmissionDisplay({ submissionId }: PhotoSubmissionDisplayP return
Loading photos...
; } + if (error) { + return ( +
+ Error loading photos: {error} +
+ Submission ID: {submissionId} +
+ ); + } + if (photos.length === 0) { - return
No photos found
; + return ( +
+ No photos found for this submission +
+ ID: {submissionId} +
+ ); } return (