Fix submission deletion and preserve filters

This commit is contained in:
gpt-engineer-app[bot]
2025-09-29 00:06:57 +00:00
parent c9cd4318d4
commit f9778dd9d9
2 changed files with 29 additions and 12 deletions

View File

@@ -1,4 +1,4 @@
import { useState, useEffect } from 'react';
import { useState, useEffect, useImperativeHandle, forwardRef } from 'react';
import { CheckCircle, XCircle, Eye, Calendar, User, Filter, MessageSquare, FileText, Image, X, Trash2 } from 'lucide-react';
import { Button } from '@/components/ui/button';
import { Badge } from '@/components/ui/badge';
@@ -28,7 +28,11 @@ interface ModerationItem {
type EntityFilter = 'all' | 'reviews' | 'submissions' | 'photos';
type StatusFilter = 'all' | 'pending' | 'flagged' | 'approved' | 'rejected';
export function ModerationQueue() {
export interface ModerationQueueRef {
refresh: () => void;
}
export const ModerationQueue = forwardRef<ModerationQueueRef>((props, ref) => {
const [items, setItems] = useState<ModerationItem[]>([]);
const [loading, setLoading] = useState(true);
const [actionLoading, setActionLoading] = useState<string | null>(null);
@@ -38,6 +42,13 @@ export function ModerationQueue() {
const { toast } = useToast();
const { isAdmin, isSuperuser } = useUserRole();
// Expose refresh method via ref
useImperativeHandle(ref, () => ({
refresh: () => {
fetchItems(activeEntityFilter, activeStatusFilter);
}
}), [activeEntityFilter, activeStatusFilter]);
const fetchItems = async (entityFilter: EntityFilter = 'all', statusFilter: StatusFilter = 'pending') => {
try {
setLoading(true);
@@ -292,8 +303,14 @@ export function ModerationQueue() {
const photoIds: string[] = [];
if (item.content?.photos && Array.isArray(item.content.photos)) {
for (const photo of item.content.photos) {
if (photo.imageId) {
photoIds.push(photo.imageId);
if (photo.url) {
// Extract UUID from blob URL: blob:https://domain/[uuid]
const urlParts = photo.url.split('/');
const imageId = urlParts[urlParts.length - 1];
// Basic UUID validation (should be at least 32 characters)
if (imageId && imageId.length >= 32) {
photoIds.push(imageId);
}
}
}
}
@@ -755,4 +772,4 @@ export function ModerationQueue() {
<QueueContent />
</div>
);
}
});