mirror of
https://github.com/pacnpal/thrilltrack-explorer.git
synced 2025-12-22 14:31:12 -05:00
Fix: Stabilize realtime subscription callbacks
This commit is contained in:
@@ -936,10 +936,10 @@ export function useModerationQueueManager(config: ModerationQueueManagerConfig):
|
|||||||
},
|
},
|
||||||
entityCache,
|
entityCache,
|
||||||
profileCache,
|
profileCache,
|
||||||
recentlyRemovedIds: recentlyRemovedRef.current,
|
recentlyRemovedIds: recentlyRemovedRef.current,
|
||||||
interactingWithIds: interactingWith,
|
interactingWithIds: interactingWith,
|
||||||
currentItems: items,
|
currentItemsRef: itemsRef,
|
||||||
});
|
});
|
||||||
|
|
||||||
return {
|
return {
|
||||||
items,
|
items,
|
||||||
|
|||||||
@@ -61,8 +61,8 @@ export interface RealtimeSubscriptionConfig {
|
|||||||
/** Set of IDs currently being interacted with */
|
/** Set of IDs currently being interacted with */
|
||||||
interactingWithIds: Set<string>;
|
interactingWithIds: Set<string>;
|
||||||
|
|
||||||
/** Current items in queue (for comparison) */
|
/** Current items in queue (for comparison) - using ref to avoid reconnections */
|
||||||
currentItems: ModerationItem[];
|
currentItemsRef: React.MutableRefObject<ModerationItem[]>;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -97,7 +97,7 @@ export function useRealtimeSubscriptions(
|
|||||||
profileCache,
|
profileCache,
|
||||||
recentlyRemovedIds,
|
recentlyRemovedIds,
|
||||||
interactingWithIds,
|
interactingWithIds,
|
||||||
currentItems,
|
currentItemsRef,
|
||||||
} = config;
|
} = config;
|
||||||
|
|
||||||
// Debounce management for UPDATE events
|
// Debounce management for UPDATE events
|
||||||
@@ -339,7 +339,7 @@ export function useRealtimeSubscriptions(
|
|||||||
const matchesEntity = matchesEntityFilter(updatedSubmission, filters.entityFilter);
|
const matchesEntity = matchesEntityFilter(updatedSubmission, filters.entityFilter);
|
||||||
const matchesStatus = matchesStatusFilter(updatedSubmission, filters.statusFilter);
|
const matchesStatus = matchesStatusFilter(updatedSubmission, filters.statusFilter);
|
||||||
|
|
||||||
const wasInQueue = currentItems.some(i => i.id === updatedSubmission.id);
|
const wasInQueue = currentItemsRef.current.some(i => i.id === updatedSubmission.id);
|
||||||
const shouldBeInQueue = matchesEntity && matchesStatus;
|
const shouldBeInQueue = matchesEntity && matchesStatus;
|
||||||
|
|
||||||
if (wasInQueue && !shouldBeInQueue) {
|
if (wasInQueue && !shouldBeInQueue) {
|
||||||
@@ -375,7 +375,7 @@ export function useRealtimeSubscriptions(
|
|||||||
);
|
);
|
||||||
|
|
||||||
// Check if item actually changed
|
// Check if item actually changed
|
||||||
const currentItem = currentItems.find(i => i.id === fullItem.id);
|
const currentItem = currentItemsRef.current.find(i => i.id === fullItem.id);
|
||||||
if (currentItem && !hasItemChanged(currentItem, fullItem)) {
|
if (currentItem && !hasItemChanged(currentItem, fullItem)) {
|
||||||
console.log('✅ Realtime UPDATE: No changes detected for', fullItem.id);
|
console.log('✅ Realtime UPDATE: No changes detected for', fullItem.id);
|
||||||
return;
|
return;
|
||||||
@@ -392,7 +392,6 @@ export function useRealtimeSubscriptions(
|
|||||||
pauseWhenHidden,
|
pauseWhenHidden,
|
||||||
recentlyRemovedIds,
|
recentlyRemovedIds,
|
||||||
interactingWithIds,
|
interactingWithIds,
|
||||||
currentItems,
|
|
||||||
debouncedUpdate,
|
debouncedUpdate,
|
||||||
fetchSubmissionDetails,
|
fetchSubmissionDetails,
|
||||||
profileCache,
|
profileCache,
|
||||||
|
|||||||
Reference in New Issue
Block a user