larxius commited on
Commit
80d9b3b
Β·
verified Β·
1 Parent(s): 7f7dc5f

Update frontend/src/pages/Dashboard.jsx

Browse files
Files changed (1) hide show
  1. 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
- logPollRef.current = setInterval(async () => {
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
- }, 1500);
 
 
 
 
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
- // Validate it's still running before starting the poller
212
- fetch(`/api/scans/${storedScan.id}/logs`, {
213
- headers: { 'Authorization': `Bearer ${getToken()}` }
214
- }).then(async (r) => {
215
- if (r.ok) {
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
  }