fix: reduce dashboard request churn
This commit is contained in:
@@ -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) =>
|
||||
|
||||
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user