mirror of
https://github.com/pacnpal/thrilltrack-explorer.git
synced 2025-12-22 14:51:13 -05:00
Fix request storm in Admin panel
This commit is contained in:
@@ -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 (
|
||||
|
||||
Reference in New Issue
Block a user