mirror of
https://github.com/pacnpal/thrilltrack-explorer.git
synced 2025-12-21 05:11:13 -05:00
Fix moderation queue infinite refresh
This commit is contained in:
@@ -33,6 +33,7 @@ interface ModerationItem {
|
||||
type: 'review' | 'content_submission';
|
||||
content: any;
|
||||
created_at: string;
|
||||
updated_at?: string;
|
||||
user_id: string;
|
||||
status: string;
|
||||
submission_type?: string;
|
||||
@@ -125,10 +126,9 @@ export const ModerationQueue = forwardRef<ModerationQueueRef>((props, ref) => {
|
||||
preserveInteractionRef.current = preserveInteraction;
|
||||
}, [refreshStrategy, preserveInteraction]);
|
||||
|
||||
// Sync itemsRef and loadedIdsRef with items state
|
||||
// Only sync itemsRef (not loadedIdsRef) to avoid breaking silent polling logic
|
||||
useEffect(() => {
|
||||
itemsRef.current = items;
|
||||
loadedIdsRef.current = new Set(items.map(item => item.id));
|
||||
}, [items]);
|
||||
|
||||
const fetchItems = useCallback(async (entityFilter: EntityFilter = 'all', statusFilter: StatusFilter = 'pending', silent = false, tab: QueueTab = 'mainQueue') => {
|
||||
@@ -435,8 +435,13 @@ export const ModerationQueue = forwardRef<ModerationQueueRef>((props, ref) => {
|
||||
const currentPreserveInteraction = preserveInteractionRef.current;
|
||||
|
||||
if (silent) {
|
||||
// Update timestamp for next poll
|
||||
lastFetchTimestampRef.current = new Date().toISOString();
|
||||
// Update timestamp using actual data timestamps, not current time
|
||||
if (moderationItems.length > 0) {
|
||||
const maxTimestamp = Math.max(
|
||||
...moderationItems.map(item => new Date(item.updated_at || item.created_at).getTime())
|
||||
);
|
||||
lastFetchTimestampRef.current = new Date(maxTimestamp).toISOString();
|
||||
}
|
||||
|
||||
// Background polling: behavior controlled by admin settings
|
||||
const currentLoadedIds = loadedIdsRef.current;
|
||||
@@ -469,10 +474,17 @@ export const ModerationQueue = forwardRef<ModerationQueueRef>((props, ref) => {
|
||||
break;
|
||||
|
||||
case 'merge':
|
||||
// Add new items to end of existing queue
|
||||
// Only add submissions that are genuinely NEW (not in current queue)
|
||||
if (newSubmissions.length > 0) {
|
||||
setItems(prev => [...prev, ...newSubmissions]);
|
||||
console.log('🔀 Queue merged - added', newSubmissions.length, 'new items');
|
||||
const currentIds = new Set(itemsRef.current.map(item => item.id));
|
||||
const trulyNewSubmissions = newSubmissions.filter(item => !currentIds.has(item.id));
|
||||
|
||||
if (trulyNewSubmissions.length > 0) {
|
||||
setItems(prev => [...prev, ...trulyNewSubmissions]);
|
||||
console.log('🔀 Queue merged - added', trulyNewSubmissions.length, 'truly new items');
|
||||
} else {
|
||||
console.log('✅ No new items - existing submissions unchanged');
|
||||
}
|
||||
} else {
|
||||
console.log('✅ Queue frozen (merge mode) - no new items to add');
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user