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