Spaces:
Running on CPU Upgrade
Running on CPU Upgrade
Update frontend/src/pages/Dashboard.jsx
Browse files- frontend/src/pages/Dashboard.jsx +11 -18
frontend/src/pages/Dashboard.jsx
CHANGED
|
@@ -87,7 +87,7 @@ export const Dashboard = () => {
|
|
| 87 |
let consecutiveErrors = 0;
|
| 88 |
const MAX_ERRORS = 20; // tolerate up to 20 failures (covers token refresh + brief outages)
|
| 89 |
|
| 90 |
-
|
| 91 |
if (!activeScanRef.current) { stopLogPolling(); return; }
|
| 92 |
|
| 93 |
let activeToken = getToken();
|
|
@@ -133,7 +133,11 @@ export const Dashboard = () => {
|
|
| 133 |
console.error('[Dashboard] Log poll error:', err);
|
| 134 |
if (consecutiveErrors >= MAX_ERRORS) stopLogPolling();
|
| 135 |
}
|
| 136 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
| 137 |
}, [getToken, refreshAccessToken, stopLogPolling, persistActiveScan, markScanAsCompleted]);
|
| 138 |
|
| 139 |
// ββ Dashboard Data Fetch βββββββββββββββββββββββββββββββββββββ
|
|
@@ -208,22 +212,11 @@ export const Dashboard = () => {
|
|
| 208 |
if (stored && token) {
|
| 209 |
try {
|
| 210 |
const storedScan = JSON.parse(stored);
|
| 211 |
-
|
| 212 |
-
|
| 213 |
-
|
| 214 |
-
|
| 215 |
-
|
| 216 |
-
const d = await r.json();
|
| 217 |
-
if (d.status === 'scanning' || d.status === 'queued') {
|
| 218 |
-
setActiveScan(storedScan);
|
| 219 |
-
setLiveLogs(d.logs || []);
|
| 220 |
-
startLogPolling(storedScan);
|
| 221 |
-
} else {
|
| 222 |
-
// Scan already done β clean up localStorage
|
| 223 |
-
localStorage.removeItem(ACTIVE_SCAN_KEY);
|
| 224 |
-
}
|
| 225 |
-
}
|
| 226 |
-
}).catch(() => {});
|
| 227 |
} catch (_) {
|
| 228 |
localStorage.removeItem(ACTIVE_SCAN_KEY);
|
| 229 |
}
|
|
|
|
| 87 |
let consecutiveErrors = 0;
|
| 88 |
const MAX_ERRORS = 20; // tolerate up to 20 failures (covers token refresh + brief outages)
|
| 89 |
|
| 90 |
+
const pollLogs = async () => {
|
| 91 |
if (!activeScanRef.current) { stopLogPolling(); return; }
|
| 92 |
|
| 93 |
let activeToken = getToken();
|
|
|
|
| 133 |
console.error('[Dashboard] Log poll error:', err);
|
| 134 |
if (consecutiveErrors >= MAX_ERRORS) stopLogPolling();
|
| 135 |
}
|
| 136 |
+
};
|
| 137 |
+
|
| 138 |
+
// Execute immediately on start for instant response without 1.5s delay
|
| 139 |
+
pollLogs();
|
| 140 |
+
logPollRef.current = setInterval(pollLogs, 1500);
|
| 141 |
}, [getToken, refreshAccessToken, stopLogPolling, persistActiveScan, markScanAsCompleted]);
|
| 142 |
|
| 143 |
// ββ Dashboard Data Fetch βββββββββββββββββββββββββββββββββββββ
|
|
|
|
| 212 |
if (stored && token) {
|
| 213 |
try {
|
| 214 |
const storedScan = JSON.parse(stored);
|
| 215 |
+
if (storedScan && storedScan.id) {
|
| 216 |
+
setActiveScan(storedScan);
|
| 217 |
+
activeScanRef.current = storedScan;
|
| 218 |
+
startLogPolling(storedScan);
|
| 219 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 220 |
} catch (_) {
|
| 221 |
localStorage.removeItem(ACTIVE_SCAN_KEY);
|
| 222 |
}
|