Fix admin page flashing

This commit is contained in:
gpt-engineer-app[bot]
2025-10-09 17:14:45 +00:00
parent ff7c90e62d
commit 356cf2b54b
4 changed files with 69 additions and 36 deletions

View File

@@ -102,18 +102,33 @@ export const useModerationStats = (options: UseModerationStatsOptions = {}) => {
statsDebounceRef.current = setTimeout(() => {
fetchStats(true); // Silent refresh
}, 500); // 500ms debounce
}, 2000); // 2 second debounce to reduce flashing
}, [fetchStats]);
// Realtime subscription for instant stat updates
// Realtime subscription - only trigger on INSERT of new pending items
useEffect(() => {
if (!enabled || !realtimeEnabled) return;
const channel = supabase
.channel('moderation-stats-realtime')
.on('postgres_changes', { event: '*', schema: 'public', table: 'content_submissions' }, debouncedFetchStats)
.on('postgres_changes', { event: '*', schema: 'public', table: 'reports' }, debouncedFetchStats)
.on('postgres_changes', { event: '*', schema: 'public', table: 'reviews' }, debouncedFetchStats)
.on('postgres_changes', {
event: 'INSERT',
schema: 'public',
table: 'content_submissions',
filter: 'status=eq.pending'
}, debouncedFetchStats)
.on('postgres_changes', {
event: 'INSERT',
schema: 'public',
table: 'reports',
filter: 'status=eq.pending'
}, debouncedFetchStats)
.on('postgres_changes', {
event: '*',
schema: 'public',
table: 'reviews',
filter: 'moderation_status=eq.flagged'
}, debouncedFetchStats)
.subscribe();
return () => {