mirror of
https://github.com/pacnpal/thrilltrack-explorer.git
synced 2025-12-20 12:31:26 -05:00
Fix unstable callbacks in moderation queue
This commit is contained in:
@@ -135,8 +135,10 @@ export const ModerationQueue = forwardRef<ModerationQueueRef, ModerationQueuePro
|
|||||||
}, [queueManager, toast]);
|
}, [queueManager, toast]);
|
||||||
|
|
||||||
// Fetch active locks count for superusers
|
// Fetch active locks count for superusers
|
||||||
|
const isSuperuserValue = isSuperuser();
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!isSuperuser()) return;
|
if (!isSuperuserValue) return;
|
||||||
|
|
||||||
const fetchActiveLocksCount = async () => {
|
const fetchActiveLocksCount = async () => {
|
||||||
const { count } = await supabase
|
const { count } = await supabase
|
||||||
@@ -153,7 +155,7 @@ export const ModerationQueue = forwardRef<ModerationQueueRef, ModerationQueuePro
|
|||||||
// Refresh count periodically
|
// Refresh count periodically
|
||||||
const interval = setInterval(fetchActiveLocksCount, 30000); // Every 30s
|
const interval = setInterval(fetchActiveLocksCount, 30000); // Every 30s
|
||||||
return () => clearInterval(interval);
|
return () => clearInterval(interval);
|
||||||
}, [isSuperuser]);
|
}, [isSuperuserValue]);
|
||||||
|
|
||||||
// Track if lock was restored from database
|
// Track if lock was restored from database
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
|||||||
@@ -136,13 +136,13 @@ export function useModerationQueueManager(config: ModerationQueueManagerConfig):
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Use a stable callback via ref to prevent excessive re-renders
|
||||||
|
const lockStateChangeHandlerRef = useRef<() => void>();
|
||||||
|
|
||||||
const queue = useModerationQueue({
|
const queue = useModerationQueue({
|
||||||
onLockStateChange: () => {
|
onLockStateChange: useCallback(() => {
|
||||||
logger.log('🔄 Lock state changed, invalidating queue cache');
|
lockStateChangeHandlerRef.current?.();
|
||||||
queueQuery.invalidate();
|
}, [])
|
||||||
// Force immediate re-render by triggering a loading cycle
|
|
||||||
setLoadingState(prev => prev === "loading" ? "ready" : prev);
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
const entityCache = useEntityCache();
|
const entityCache = useEntityCache();
|
||||||
const profileCache = useProfileCache();
|
const profileCache = useProfileCache();
|
||||||
@@ -177,6 +177,13 @@ export function useModerationQueueManager(config: ModerationQueueManagerConfig):
|
|||||||
enabled: !!user,
|
enabled: !!user,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Update the lock state change handler ref whenever queueQuery changes
|
||||||
|
lockStateChangeHandlerRef.current = () => {
|
||||||
|
logger.log('🔄 Lock state changed, invalidating queue cache');
|
||||||
|
queueQuery.invalidate();
|
||||||
|
setLoadingState(prev => prev === "loading" ? "ready" : prev);
|
||||||
|
};
|
||||||
|
|
||||||
// Update items when query data changes
|
// Update items when query data changes
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (queueQuery.items) {
|
if (queueQuery.items) {
|
||||||
|
|||||||
Reference in New Issue
Block a user