mirror of
https://github.com/pacnpal/thrilltrack-explorer.git
synced 2025-12-21 10:11:12 -05:00
Fix random moderation queue reloads
This commit is contained in:
@@ -950,7 +950,7 @@ export const ModerationQueue = forwardRef<ModerationQueueRef>((props, ref) => {
|
||||
const newTimeout = setTimeout(() => {
|
||||
updateFn();
|
||||
realtimeUpdateDebounceRef.current.delete(submissionId);
|
||||
}, 500); // Wait 500ms after last event
|
||||
}, 1000); // Wait 1000ms after last event
|
||||
|
||||
realtimeUpdateDebounceRef.current.set(submissionId, newTimeout);
|
||||
}, []);
|
||||
@@ -1076,26 +1076,23 @@ export const ModerationQueue = forwardRef<ModerationQueueRef>((props, ref) => {
|
||||
const hasChanged =
|
||||
currentItem.status !== fullItem.status ||
|
||||
currentItem.reviewed_at !== fullItem.reviewed_at ||
|
||||
currentItem.reviewed_by !== fullItem.reviewed_by ||
|
||||
currentItem.reviewer_notes !== fullItem.reviewer_notes ||
|
||||
currentItem.assigned_to !== fullItem.assigned_to ||
|
||||
currentItem.locked_until !== fullItem.locked_until ||
|
||||
currentItem.escalated !== fullItem.escalated ||
|
||||
JSON.stringify(currentItem.content) !== JSON.stringify(fullItem.content);
|
||||
|
||||
if (!hasChanged) {
|
||||
console.log('✅ Realtime UPDATE: No changes detected for', fullItem.id);
|
||||
return prev; // Keep existing array reference
|
||||
return prev; // Keep existing array reference - PREVENTS RE-RENDER
|
||||
}
|
||||
|
||||
console.log('🔄 Realtime UPDATE: Changes detected for', fullItem.id);
|
||||
const newItems = prev.map(i => i.id === fullItem.id ? fullItem : i);
|
||||
itemsRef.current = newItems; // Update ref immediately
|
||||
return newItems;
|
||||
// Shallow merge to preserve stable references
|
||||
return prev.map(i => i.id === fullItem.id ? { ...i, ...fullItem } : i);
|
||||
} else {
|
||||
console.log('🆕 Realtime UPDATE: Adding new item', fullItem.id);
|
||||
const newItems = [fullItem, ...prev];
|
||||
itemsRef.current = newItems; // Update ref immediately
|
||||
return newItems;
|
||||
return [fullItem, ...prev];
|
||||
}
|
||||
});
|
||||
} catch (error) {
|
||||
|
||||
Reference in New Issue
Block a user