Fix auto-refresh and queue claiming

This commit is contained in:
gpt-engineer-app[bot]
2025-10-06 19:01:49 +00:00
parent e1e8fa2ddc
commit cc3ec7a6e4
2 changed files with 37 additions and 12 deletions

View File

@@ -354,25 +354,38 @@ export const ModerationQueue = forwardRef<ModerationQueueRef>((props, ref) => {
})),
];
// Sort by creation date (newest first for better UX)
formattedItems.sort((a, b) => new Date(b.created_at).getTime() - new Date(a.created_at).getTime());
// Sort by creation date (newest first) with stable secondary sort by ID
formattedItems.sort((a, b) => {
const timeA = new Date(a.created_at).getTime();
const timeB = new Date(b.created_at).getTime();
// Primary sort by time
if (timeA !== timeB) {
return timeB - timeA;
}
// Secondary stable sort by ID for items with identical timestamps
return a.id.localeCompare(b.id);
});
// Use smart merging for silent refreshes if strategy is 'merge'
if (silent && refreshStrategy === 'merge') {
const mergeResult = smartMergeArray(items, formattedItems, {
compareFields: ['status', 'reviewed_at', 'reviewer_notes'],
compareFields: ['status', 'reviewed_at', 'reviewed_by', 'reviewer_notes', 'content', 'submission_type'],
preserveOrder: true,
addToTop: true,
});
// If there are changes and we should preserve interaction
// If there are changes
if (mergeResult.hasChanges) {
const actuallyNewItems = mergeResult.changes.added.length;
// Debug logging for smart merge
console.log('🔄 Smart merge detected changes:', {
added: mergeResult.changes.added.length,
added: actuallyNewItems,
updated: mergeResult.changes.updated.length,
removed: mergeResult.changes.removed.length,
newItemsCount: mergeResult.changes.added.length,
totalItems: mergeResult.items.length,
protectedIds: Array.from(preserveInteraction ? interactingWith : new Set<string>()),
strategy: refreshStrategy,
preserveInteraction
@@ -391,10 +404,13 @@ export const ModerationQueue = forwardRef<ModerationQueueRef>((props, ref) => {
setItems(mergedWithProtection);
// Update new items count
if (mergeResult.changes.added.length > 0) {
setNewItemsCount(prev => prev + mergeResult.changes.added.length);
// Only set new items count if there are genuinely new items
if (actuallyNewItems > 0) {
setNewItemsCount(actuallyNewItems);
}
} else {
// No changes detected - keep current state completely unchanged
console.log('✅ No changes detected, keeping current state');
}
} else {
// Full replacement for non-silent refreshes or 'replace' strategy