mirror of
https://github.com/pacnpal/thrilltrack-explorer.git
synced 2025-12-22 09:11:13 -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) {
|
||||
|
||||
@@ -670,7 +670,6 @@ export const QueueItem = memo(({
|
||||
|
||||
// Deep comparison of content and other fields that affect rendering
|
||||
if (prevProps.item.reviewed_at !== nextProps.item.reviewed_at) return false;
|
||||
if (prevProps.item.reviewed_by !== nextProps.item.reviewed_by) return false;
|
||||
if (prevProps.item.reviewer_notes !== nextProps.item.reviewer_notes) return false;
|
||||
if (prevProps.item.assigned_to !== nextProps.item.assigned_to) return false;
|
||||
if (prevProps.item.locked_until !== nextProps.item.locked_until) return false;
|
||||
|
||||
Reference in New Issue
Block a user