fix: reduce dashboard request churn
This commit is contained in:
@@ -30,10 +30,6 @@ export function RequestHistory() {
|
|||||||
socket.off("request_updated", refresh);
|
socket.off("request_updated", refresh);
|
||||||
};
|
};
|
||||||
}, [socket, status]);
|
}, [socket, status]);
|
||||||
useEffect(() => {
|
|
||||||
const id = setInterval(load, 15000);
|
|
||||||
return () => clearInterval(id);
|
|
||||||
}, [status]);
|
|
||||||
|
|
||||||
const filtered = requests.filter(
|
const filtered = requests.filter(
|
||||||
(r) =>
|
(r) =>
|
||||||
|
|||||||
@@ -43,17 +43,18 @@ export default function DashboardPage() {
|
|||||||
router.push("/login");
|
router.push("/login");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
loadData();
|
loadWalletAndPending();
|
||||||
|
loadCosts();
|
||||||
}, [isAuthenticated, router]);
|
}, [isAuthenticated, router]);
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const id = setInterval(() => {
|
const id = setInterval(() => {
|
||||||
if (isAuthenticated) loadData();
|
if (isAuthenticated) loadWalletAndPending();
|
||||||
}, 15000);
|
}, 30000);
|
||||||
return () => clearInterval(id);
|
return () => clearInterval(id);
|
||||||
}, [isAuthenticated]);
|
}, [isAuthenticated]);
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!socket) return;
|
if (!socket) return;
|
||||||
const refresh = () => loadData();
|
const refresh = () => loadWalletAndPending();
|
||||||
socket.on("credits_earned", refresh);
|
socket.on("credits_earned", refresh);
|
||||||
socket.on("bonus_received", refresh);
|
socket.on("bonus_received", refresh);
|
||||||
socket.on("credits_spent", refresh);
|
socket.on("credits_spent", refresh);
|
||||||
@@ -66,15 +67,13 @@ export default function DashboardPage() {
|
|||||||
};
|
};
|
||||||
}, [socket]);
|
}, [socket]);
|
||||||
|
|
||||||
const loadData = async () => {
|
const loadWalletAndPending = async () => {
|
||||||
try {
|
try {
|
||||||
const [walletRes, costsRes, reqRes] = await Promise.all([
|
const [walletRes, reqRes] = await Promise.all([
|
||||||
api.get("/wallet"),
|
api.get("/wallet"),
|
||||||
overseerApi.getCosts(),
|
|
||||||
userApi.getRequests(1, 10, "PENDING"),
|
userApi.getRequests(1, 10, "PENDING"),
|
||||||
]);
|
]);
|
||||||
setWallet(walletRes.data);
|
setWallet(walletRes.data);
|
||||||
setRequestCosts(costsRes.data);
|
|
||||||
setPendingRequests(reqRes.data.requests || []);
|
setPendingRequests(reqRes.data.requests || []);
|
||||||
} catch {
|
} catch {
|
||||||
toast.error("Failed to load dashboard");
|
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 () => {
|
const handleLogout = async () => {
|
||||||
try {
|
try {
|
||||||
await authApi.logout();
|
await authApi.logout();
|
||||||
|
|||||||
Reference in New Issue
Block a user