larxius commited on
Commit
40b2b0b
·
verified ·
1 Parent(s): 80d9b3b

Update frontend/src/pages/Dashboard.jsx

Browse files
Files changed (1) hide show
  1. frontend/src/pages/Dashboard.jsx +6 -5
frontend/src/pages/Dashboard.jsx CHANGED
@@ -88,12 +88,13 @@ export const Dashboard = () => {
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();
94
 
95
  try {
96
- let res = await fetch(`/api/scans/${scan.id}/logs`, {
97
  headers: { 'Authorization': `Bearer ${activeToken}` }
98
  });
99
 
@@ -102,7 +103,7 @@ export const Dashboard = () => {
102
  const newToken = await refreshAccessToken();
103
  if (newToken) {
104
  activeToken = newToken;
105
- res = await fetch(`/api/scans/${scan.id}/logs`, {
106
  headers: { 'Authorization': `Bearer ${newToken}` }
107
  });
108
  }
@@ -116,7 +117,7 @@ export const Dashboard = () => {
116
 
117
  consecutiveErrors = 0;
118
  const data = await res.json();
119
- if (data.logs && data.logs.length > 0) {
120
  setLiveLogs(data.logs);
121
  }
122
 
@@ -125,7 +126,7 @@ export const Dashboard = () => {
125
  setActiveScan(null);
126
  activeScanRef.current = null;
127
  persistActiveScan(null); // clear localStorage
128
- markScanAsCompleted(scan.id);
129
  fetchDashboard();
130
  }
131
  } catch (err) {
 
88
  const MAX_ERRORS = 20; // tolerate up to 20 failures (covers token refresh + brief outages)
89
 
90
  const pollLogs = async () => {
91
+ const currentScan = activeScanRef.current || scan;
92
+ if (!currentScan) { stopLogPolling(); return; }
93
 
94
  let activeToken = getToken();
95
 
96
  try {
97
+ let res = await fetch(`/api/scans/${currentScan.id}/logs`, {
98
  headers: { 'Authorization': `Bearer ${activeToken}` }
99
  });
100
 
 
103
  const newToken = await refreshAccessToken();
104
  if (newToken) {
105
  activeToken = newToken;
106
+ res = await fetch(`/api/scans/${currentScan.id}/logs`, {
107
  headers: { 'Authorization': `Bearer ${newToken}` }
108
  });
109
  }
 
117
 
118
  consecutiveErrors = 0;
119
  const data = await res.json();
120
+ if (data.logs) {
121
  setLiveLogs(data.logs);
122
  }
123
 
 
126
  setActiveScan(null);
127
  activeScanRef.current = null;
128
  persistActiveScan(null); // clear localStorage
129
+ markScanAsCompleted(currentScan.id);
130
  fetchDashboard();
131
  }
132
  } catch (err) {