larxius commited on
Commit
6ae8263
Β·
verified Β·
1 Parent(s): fbd9888

Update frontend/src/pages/Dashboard.jsx

Browse files
Files changed (1) hide show
  1. frontend/src/pages/Dashboard.jsx +15 -3
frontend/src/pages/Dashboard.jsx CHANGED
@@ -43,6 +43,13 @@ export const Dashboard = () => {
43
  const logPollRef = useRef(null);
44
  const dashboardPollRef = useRef(null);
45
  const activeScanRef = useRef(null);
 
 
 
 
 
 
 
46
  // Always read the latest token from localStorage so the poller works even
47
  // after a token refresh (avoids stale closure issues)
48
  const getToken = useCallback(() =>
@@ -118,7 +125,7 @@ export const Dashboard = () => {
118
  setActiveScan(null);
119
  activeScanRef.current = null;
120
  persistActiveScan(null); // clear localStorage
121
- setCompletedScanId(scan.id);
122
  fetchDashboard();
123
  }
124
  } catch (err) {
@@ -127,7 +134,7 @@ export const Dashboard = () => {
127
  if (consecutiveErrors >= MAX_ERRORS) stopLogPolling();
128
  }
129
  }, 1500);
130
- }, [getToken, refreshAccessToken, stopLogPolling, persistActiveScan]);
131
 
132
  // ── Dashboard Data Fetch ─────────────────────────────────────
133
  const fetchDashboard = useCallback(async () => {
@@ -148,7 +155,7 @@ export const Dashboard = () => {
148
  setLastUpdated(new Date());
149
 
150
  const running = (historyData.scans || []).find(
151
- s => s.status === 'scanning' || s.status === 'queued'
152
  );
153
 
154
  if (running) {
@@ -162,6 +169,11 @@ export const Dashboard = () => {
162
  activeScanRef.current = null;
163
  persistActiveScan(null);
164
  stopLogPolling();
 
 
 
 
 
165
  }
166
  } catch (err) {
167
  console.error('[Dashboard] Fetch error:', err);
 
43
  const logPollRef = useRef(null);
44
  const dashboardPollRef = useRef(null);
45
  const activeScanRef = useRef(null);
46
+ const completedScanIdRef = useRef(null);
47
+
48
+ const markScanAsCompleted = useCallback((id) => {
49
+ completedScanIdRef.current = id;
50
+ setCompletedScanId(id);
51
+ }, []);
52
+
53
  // Always read the latest token from localStorage so the poller works even
54
  // after a token refresh (avoids stale closure issues)
55
  const getToken = useCallback(() =>
 
125
  setActiveScan(null);
126
  activeScanRef.current = null;
127
  persistActiveScan(null); // clear localStorage
128
+ markScanAsCompleted(scan.id);
129
  fetchDashboard();
130
  }
131
  } catch (err) {
 
134
  if (consecutiveErrors >= MAX_ERRORS) stopLogPolling();
135
  }
136
  }, 1500);
137
+ }, [getToken, refreshAccessToken, stopLogPolling, persistActiveScan, markScanAsCompleted]);
138
 
139
  // ── Dashboard Data Fetch ─────────────────────────────────────
140
  const fetchDashboard = useCallback(async () => {
 
155
  setLastUpdated(new Date());
156
 
157
  const running = (historyData.scans || []).find(
158
+ s => (s.status === 'scanning' || s.status === 'queued') && s.id !== completedScanIdRef.current
159
  );
160
 
161
  if (running) {
 
169
  activeScanRef.current = null;
170
  persistActiveScan(null);
171
  stopLogPolling();
172
+ } else if (!running && activeScanRef.current && activeScanRef.current.id === completedScanIdRef.current) {
173
+ setActiveScan(null);
174
+ activeScanRef.current = null;
175
+ persistActiveScan(null);
176
+ stopLogPolling();
177
  }
178
  } catch (err) {
179
  console.error('[Dashboard] Fetch error:', err);