diff --git a/frontend/src/app/dashboard/components/RequestHistory.tsx b/frontend/src/app/dashboard/components/RequestHistory.tsx index 15b73ab..6c751d5 100644 --- a/frontend/src/app/dashboard/components/RequestHistory.tsx +++ b/frontend/src/app/dashboard/components/RequestHistory.tsx @@ -30,10 +30,6 @@ export function RequestHistory() { socket.off("request_updated", refresh); }; }, [socket, status]); - useEffect(() => { - const id = setInterval(load, 15000); - return () => clearInterval(id); - }, [status]); const filtered = requests.filter( (r) => diff --git a/frontend/src/app/dashboard/page.tsx b/frontend/src/app/dashboard/page.tsx index 0b7257b..0253bf8 100644 --- a/frontend/src/app/dashboard/page.tsx +++ b/frontend/src/app/dashboard/page.tsx @@ -43,17 +43,18 @@ export default function DashboardPage() { router.push("/login"); return; } - loadData(); + loadWalletAndPending(); + loadCosts(); }, [isAuthenticated, router]); useEffect(() => { const id = setInterval(() => { - if (isAuthenticated) loadData(); - }, 15000); + if (isAuthenticated) loadWalletAndPending(); + }, 30000); return () => clearInterval(id); }, [isAuthenticated]); useEffect(() => { if (!socket) return; - const refresh = () => loadData(); + const refresh = () => loadWalletAndPending(); socket.on("credits_earned", refresh); socket.on("bonus_received", refresh); socket.on("credits_spent", refresh); @@ -66,15 +67,13 @@ export default function DashboardPage() { }; }, [socket]); - const loadData = async () => { + const loadWalletAndPending = async () => { try { - const [walletRes, costsRes, reqRes] = await Promise.all([ + const [walletRes, reqRes] = await Promise.all([ api.get("/wallet"), - overseerApi.getCosts(), userApi.getRequests(1, 10, "PENDING"), ]); setWallet(walletRes.data); - setRequestCosts(costsRes.data); setPendingRequests(reqRes.data.requests || []); } catch { toast.error("Failed to load dashboard"); @@ -83,6 +82,15 @@ export default function DashboardPage() { } }; + const loadCosts = async () => { + try { + const costsRes = await overseerApi.getCosts(); + setRequestCosts(costsRes.data); + } catch { + /* ignore */ + } + }; + const handleLogout = async () => { try { await authApi.logout();