From b778fc95f632d3ce3c685b14b7b14b26f10b6812 Mon Sep 17 00:00:00 2001 From: "gpt-engineer-app[bot]" <159125892+gpt-engineer-app[bot]@users.noreply.github.com> Date: Fri, 3 Oct 2025 14:24:43 +0000 Subject: [PATCH] Refactor: Implement Phase 3C cleanup --- src/components/homepage/HeroSearch.tsx | 1 - src/components/moderation/ModerationQueue.tsx | 70 ++------------- src/components/upload/PhotoUpload.tsx | 11 +-- src/hooks/useAuth.tsx | 2 - src/lib/entityTransformers.ts | 31 +++++-- src/types/submission-data.ts | 85 +++++++++++++++++++ 6 files changed, 119 insertions(+), 81 deletions(-) create mode 100644 src/types/submission-data.ts diff --git a/src/components/homepage/HeroSearch.tsx b/src/components/homepage/HeroSearch.tsx index bef0dc17..54516ac3 100644 --- a/src/components/homepage/HeroSearch.tsx +++ b/src/components/homepage/HeroSearch.tsx @@ -32,7 +32,6 @@ export function HeroSearch() { const handleSearch = () => { // Search functionality handled by AutocompleteSearch component in Header - console.log('Search params:', searchTerm, selectedType, selectedCountry); }; return ( diff --git a/src/components/moderation/ModerationQueue.tsx b/src/components/moderation/ModerationQueue.tsx index 39517ad4..0f0c1c4a 100644 --- a/src/components/moderation/ModerationQueue.tsx +++ b/src/components/moderation/ModerationQueue.tsx @@ -78,7 +78,6 @@ export const ModerationQueue = forwardRef((props, ref) => { const fetchItems = async (entityFilter: EntityFilter = 'all', statusFilter: StatusFilter = 'pending') => { if (!user) { - console.log('Skipping fetch - user not authenticated'); return; } @@ -327,9 +326,6 @@ export const ModerationQueue = forwardRef((props, ref) => { // Sort by creation date (newest first for better UX) formattedItems.sort((a, b) => new Date(b.created_at).getTime() - new Date(a.created_at).getTime()); - - console.log('Formatted items:', formattedItems); - console.log('Photo submissions:', formattedItems.filter(item => item.submission_type === 'photo')); setItems(formattedItems); } catch (error: any) { @@ -352,7 +348,6 @@ export const ModerationQueue = forwardRef((props, ref) => { // Set up realtime subscriptions const { connectionState: submissionsConnectionState, reconnect: reconnectSubmissions } = useRealtimeSubmissions({ onInsert: (payload) => { - console.log('New submission received'); toast({ title: 'New Submission', description: 'A new content submission has been added', @@ -360,7 +355,6 @@ export const ModerationQueue = forwardRef((props, ref) => { fetchItems(activeEntityFilter, activeStatusFilter); }, onUpdate: (payload) => { - console.log('Submission updated'); // Update items state directly for better UX setItems(prevItems => prevItems.map(item => @@ -371,7 +365,6 @@ export const ModerationQueue = forwardRef((props, ref) => { ); }, onDelete: (payload) => { - console.log('Submission deleted'); setItems(prevItems => prevItems.filter(item => !(item.id === payload.old.id && item.type === 'content_submission')) ); @@ -469,7 +462,6 @@ export const ModerationQueue = forwardRef((props, ref) => { ) => { // Prevent multiple clicks on the same item if (actionLoading === item.id) { - console.log('Action already in progress for item:', item.id); return; } @@ -585,8 +577,6 @@ export const ModerationQueue = forwardRef((props, ref) => { // Handle photo submissions - create photos records when approved if (action === 'approved' && item.type === 'content_submission' && item.submission_type === 'photo') { - console.log('🖼️ [PHOTO APPROVAL] Starting photo submission approval'); - try { // Fetch photo submission from new relational tables const { data: photoSubmission, error: fetchError } = await supabase @@ -599,15 +589,13 @@ export const ModerationQueue = forwardRef((props, ref) => { .eq('submission_id', item.id) .single(); - console.log('🖼️ [PHOTO APPROVAL] Fetched photo submission:', photoSubmission); - if (fetchError || !photoSubmission) { - console.error('🖼️ [PHOTO APPROVAL] ERROR: Failed to fetch photo submission:', fetchError); + console.error('Failed to fetch photo submission:', fetchError); throw new Error('Failed to fetch photo submission data'); } if (!photoSubmission.items || photoSubmission.items.length === 0) { - console.error('🖼️ [PHOTO APPROVAL] ERROR: No photo items found'); + console.error('No photo items found in submission'); throw new Error('No photos found in submission'); } @@ -617,10 +605,7 @@ export const ModerationQueue = forwardRef((props, ref) => { .select('id') .eq('submission_id', item.id); - console.log('🖼️ [PHOTO APPROVAL] Existing photos check:', existingPhotos); - if (existingPhotos && existingPhotos.length > 0) { - console.log('🖼️ [PHOTO APPROVAL] Photos already exist for this submission, skipping creation'); // Just update submission status const { error: updateError } = await supabase @@ -650,19 +635,15 @@ export const ModerationQueue = forwardRef((props, ref) => { approved_at: new Date().toISOString(), })); - console.log('🖼️ [PHOTO APPROVAL] Creating photo records:', photoRecords); - const { data: createdPhotos, error: insertError } = await supabase .from('photos') .insert(photoRecords) .select(); if (insertError) { - console.error('🖼️ [PHOTO APPROVAL] ERROR: Failed to insert photos:', insertError); + console.error('Failed to insert photos:', insertError); throw insertError; } - - console.log('🖼️ [PHOTO APPROVAL] ✅ Successfully created photos:', createdPhotos); } // Update submission status @@ -677,12 +658,10 @@ export const ModerationQueue = forwardRef((props, ref) => { .eq('id', item.id); if (updateError) { - console.error('🖼️ [PHOTO APPROVAL] Error updating submission:', updateError); + console.error('Error updating submission:', updateError); throw updateError; } - console.log('🖼️ [PHOTO APPROVAL] ✅ Complete! Photos approved and published'); - toast({ title: "Photos Approved", description: `Successfully approved and published ${photoSubmission.items.length} photo(s)`, @@ -693,8 +672,7 @@ export const ModerationQueue = forwardRef((props, ref) => { return; } catch (error: any) { - console.error('🖼️ [PHOTO APPROVAL] ❌ FATAL ERROR:', error); - console.error('🖼️ [PHOTO APPROVAL] Error details:', error.message, error.code, error.details); + console.error('Photo approval error:', error); throw error; } } @@ -708,8 +686,6 @@ export const ModerationQueue = forwardRef((props, ref) => { .in('status', ['pending', 'rejected']); if (!itemsError && submissionItems && submissionItems.length > 0) { - console.log(`Found ${submissionItems.length} pending submission items for ${item.id}`); - if (action === 'approved') { // Call the edge function to process all items const { data: approvalData, error: approvalError } = await supabase.functions.invoke( @@ -727,8 +703,6 @@ export const ModerationQueue = forwardRef((props, ref) => { throw new Error(`Failed to process submission items: ${approvalError.message}`); } - console.log('Submission items processed successfully:', approvalData); - toast({ title: "Submission Approved", description: `Successfully processed ${submissionItems.length} item(s)`, @@ -739,7 +713,6 @@ export const ModerationQueue = forwardRef((props, ref) => { return; } else if (action === 'rejected') { // Cascade rejection to all pending items - console.log('Cascading rejection to submission items'); const { error: rejectError } = await supabase .from('submission_items') .update({ @@ -753,8 +726,6 @@ export const ModerationQueue = forwardRef((props, ref) => { if (rejectError) { console.error('Failed to cascade rejection:', rejectError); // Don't fail the whole operation, just log it - } else { - console.log('Successfully cascaded rejection to submission items'); } } } @@ -782,8 +753,6 @@ export const ModerationQueue = forwardRef((props, ref) => { updateData.reviewer_notes = moderatorNotes; } - console.log('Updating item:', item.id, 'with data:', updateData, 'table:', table); - const { error, data } = await supabase .from(table) .update(updateData) @@ -795,16 +764,12 @@ export const ModerationQueue = forwardRef((props, ref) => { throw error; } - console.log('Update response:', { data, rowsAffected: data?.length }); - // Check if the update actually affected any rows if (!data || data.length === 0) { console.error('No rows were updated. This might be due to RLS policies or the item not existing.'); throw new Error('Failed to update item - no rows affected. You might not have permission to moderate this content.'); } - console.log('Update successful, rows affected:', data.length); - toast({ title: `Content ${action}`, description: `The ${item.type} has been ${action}`, @@ -824,10 +789,10 @@ export const ModerationQueue = forwardRef((props, ref) => { return newNotes; }); - // Only refresh if we're viewing a filter that should no longer show this item + // Refresh if needed based on filter if ((activeStatusFilter === 'pending' && (action === 'approved' || action === 'rejected')) || (activeStatusFilter === 'flagged' && (action === 'approved' || action === 'rejected'))) { - console.log('Item no longer matches filter, removing from view'); + // Item no longer matches filter } } catch (error: any) { @@ -855,7 +820,6 @@ export const ModerationQueue = forwardRef((props, ref) => { // Prevent duplicate calls if (actionLoading === item.id) { - console.log('Deletion already in progress for:', item.id); return; } @@ -865,8 +829,6 @@ export const ModerationQueue = forwardRef((props, ref) => { setItems(prev => prev.filter(i => i.id !== item.id)); try { - console.log('Starting deletion process for submission:', item.id); - // Step 1: Extract photo IDs from the submission content const photoIds: string[] = []; const validImageIds: string[] = []; @@ -876,18 +838,12 @@ export const ModerationQueue = forwardRef((props, ref) => { const photosArray = item.content?.content?.photos || item.content?.photos; if (photosArray && Array.isArray(photosArray)) { - console.log('Processing photos from content:', photosArray); for (const photo of photosArray) { - console.log('Processing photo object:', photo); - console.log('Photo keys:', Object.keys(photo)); - console.log('photo.imageId:', photo.imageId, 'type:', typeof photo.imageId); - let imageId = ''; // First try to use the stored imageId directly if (photo.imageId) { imageId = photo.imageId; - console.log('Using stored image ID:', imageId); } else if (photo.url) { // Check if this looks like a Cloudflare image ID (not a blob URL) if (photo.url.startsWith('blob:')) { @@ -909,7 +865,6 @@ export const ModerationQueue = forwardRef((props, ref) => { imageId = cloudflareMatch[1]; } } - console.log('Extracted image ID from URL:', imageId, 'from URL:', photo.url); } if (imageId) { @@ -922,14 +877,10 @@ export const ModerationQueue = forwardRef((props, ref) => { } } - console.log(`Found ${validImageIds.length} valid image IDs to delete, ${skippedPhotos.length} photos will be orphaned`); - // Step 2: Delete photos from Cloudflare Images (if any valid IDs) if (validImageIds.length > 0) { const deletePromises = validImageIds.map(async (imageId) => { try { - console.log('Attempting to delete image from Cloudflare:', imageId); - // Use Supabase SDK - automatically includes session token const { data, error } = await supabase.functions.invoke('upload-image', { method: 'DELETE', @@ -940,8 +891,6 @@ export const ModerationQueue = forwardRef((props, ref) => { throw new Error(`Failed to delete image: ${error.message}`); } - console.log('Successfully deleted image:', imageId, data); - } catch (deleteError) { console.error(`Failed to delete photo ${imageId} from Cloudflare:`, deleteError); // Continue with other deletions - don't fail the entire operation @@ -953,7 +902,6 @@ export const ModerationQueue = forwardRef((props, ref) => { } // Step 3: Delete the submission from the database - console.log('Deleting submission from database:', item.id); const { error } = await supabase .from('content_submissions') .delete() @@ -974,8 +922,6 @@ export const ModerationQueue = forwardRef((props, ref) => { if (checkData && !checkError) { console.error('DELETION FAILED: Item still exists in database after delete operation'); throw new Error('Deletion failed - item still exists in database'); - } else { - console.log('Verified: Submission successfully deleted from database'); } const deletedCount = validImageIds.length; @@ -1202,7 +1148,6 @@ export const ModerationQueue = forwardRef((props, ref) => { console.error('Failed to load review photo:', photo.url); (e.target as HTMLImageElement).style.display = 'none'; }} - onLoad={() => console.log('Review photo loaded:', photo.url)} />
@@ -1269,7 +1214,6 @@ export const ModerationQueue = forwardRef((props, ref) => { `; } }} - onLoad={() => console.log('Photo submission loaded:', photo.url)} />
diff --git a/src/components/upload/PhotoUpload.tsx b/src/components/upload/PhotoUpload.tsx index db3e6584..990cb996 100644 --- a/src/components/upload/PhotoUpload.tsx +++ b/src/components/upload/PhotoUpload.tsx @@ -275,12 +275,9 @@ export function PhotoUpload({ console.error('Failed to load avatar image:', uploadedImages[0].thumbnailUrl); e.currentTarget.src = 'data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMjQiIGhlaWdodD0iMjQiIHZpZXdCb3g9IjAgMCAyNCAyNCIgZmlsbD0ibm9uZSIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIj4KPHJlY3Qgd2lkdGg9IjI0IiBoZWlnaHQ9IjI0IiBmaWxsPSIjZjNmNGY2Ii8+CjxwYXRoIGQ9Im0xNSAxMi0zLTMtMy4wMDEgM0w2IDlsNi02aDZ2NloiIGZpbGw9IiM5Y2EzYWYiLz4KPC9zdmc+'; }} - onLoad={() => { - console.log('Avatar image loaded successfully:', uploadedImages[0].thumbnailUrl); - }} /> ) : existingPhotos.length > 0 ? ( - Avatar { - console.log('Image loaded successfully:', image.thumbnailUrl); - }} />