From 0d46ff4597407d2adb5f4d737447489eda88469a Mon Sep 17 00:00:00 2001 From: "gpt-engineer-app[bot]" <159125892+gpt-engineer-app[bot]@users.noreply.github.com> Date: Sun, 28 Sep 2025 23:34:13 +0000 Subject: [PATCH] Fix moderation status update --- src/components/moderation/ModerationQueue.tsx | 46 ++++++++++++++----- 1 file changed, 35 insertions(+), 11 deletions(-) diff --git a/src/components/moderation/ModerationQueue.tsx b/src/components/moderation/ModerationQueue.tsx index 007f3cac..00167d3e 100644 --- a/src/components/moderation/ModerationQueue.tsx +++ b/src/components/moderation/ModerationQueue.tsx @@ -185,6 +185,12 @@ export function ModerationQueue() { action: 'approved' | 'rejected', moderatorNotes?: string ) => { + // Prevent multiple clicks on the same item + if (actionLoading === item.id) { + console.log('Action already in progress for item:', item.id); + return; + } + setActionLoading(item.id); try { const table = item.type === 'review' ? 'reviews' : 'content_submissions'; @@ -209,7 +215,7 @@ export function ModerationQueue() { updateData.reviewer_notes = moderatorNotes; } - console.log('Updating item:', item.id, 'with data:', updateData); + console.log('Updating item:', item.id, 'with data:', updateData, 'table:', table); const { error, data } = await supabase .from(table) @@ -222,36 +228,54 @@ export function ModerationQueue() { throw error; } - console.log('Update successful:', data); + 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}`, }); - // Update the local state immediately + // Only update local state if the database update was successful setItems(prev => prev.map(i => i.id === item.id ? { ...i, status: action } : i )); - // Also refresh the queue after a short delay to ensure consistency - setTimeout(() => { - fetchItems(activeEntityFilter, activeStatusFilter); - }, 500); - - // Clear notes + // Clear notes only after successful update setNotes(prev => { const newNotes = { ...prev }; delete newNotes[item.id]; return newNotes; }); - } catch (error) { + + // Only refresh if we're viewing a filter that should no longer show this item + if ((activeStatusFilter === 'pending' && (action === 'approved' || action === 'rejected')) || + (activeStatusFilter === 'flagged' && (action === 'approved' || action === 'rejected'))) { + console.log('Item no longer matches filter, removing from view'); + } + + } catch (error: any) { console.error('Error moderating content:', error); + + // Revert any optimistic updates + setItems(prev => prev.map(i => + i.id === item.id + ? { ...i, status: item.status } // Revert to original status + : i + )); + toast({ title: "Error", - description: `Failed to ${action} content: ${error.message}`, + description: error.message || `Failed to ${action} content`, variant: "destructive", }); } finally {