fix: reduce dashboard request churn

This commit is contained in:
2026-04-22 14:28:07 -04:00
parent 5a8eb90c38
commit 50ca3c2900
2 changed files with 16 additions and 12 deletions
@@ -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) =>
+16 -8
View File
@@ -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();