Fix request storm in Admin panel

This commit is contained in:
gpt-engineer-app[bot]
2025-09-29 19:57:58 +00:00
parent ff52b3c905
commit 10885afa5a

View File

@@ -25,13 +25,15 @@ export default function Admin() {
flaggedContent: 0,
loading: true,
});
const [isFetching, setIsFetching] = useState(false);
const fetchStats = useCallback(async () => {
if (!user) {
console.log('Skipping stats fetch - user not authenticated');
if (!user || isFetching) {
console.log('Skipping stats fetch - user not authenticated or already fetching');
return;
}
setIsFetching(true);
try {
setStats(prev => ({ ...prev, loading: true }));
@@ -82,13 +84,15 @@ export default function Admin() {
details: error.details
});
setStats(prev => ({ ...prev, loading: false }));
} finally {
setIsFetching(false);
}
}, [user]);
}, []);
const handleRefresh = useCallback(() => {
moderationQueueRef.current?.refresh();
fetchStats(); // Also refresh stats
}, [fetchStats]);
}, []);
useEffect(() => {
if (!authLoading && !roleLoading) {
@@ -105,7 +109,7 @@ export default function Admin() {
// Fetch stats when user is authenticated and authorized
fetchStats();
}
}, [user, authLoading, roleLoading, isModerator, navigate, fetchStats]);
}, [user, authLoading, roleLoading, navigate]);
if (authLoading || roleLoading) {
return (