Skip to content

Commit dc06367

Browse files
committed
fix: Improve report processing logic in ProcessingPage component
1 parent 328ff92 commit dc06367

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

frontend/src/pages/Processing/ProcessingPage.tsx

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@ const ProcessingPage: React.FC = () => {
2222
const [isProcessing, setIsProcessing] = useState(true);
2323
const [processingError, setProcessingError] = useState<string | null>(null);
2424
const statusCheckIntervalRef = useRef<number | null>(null);
25+
const hasInitiatedProcessing = useRef(false);
2526

2627
// Get the location state which may contain the reportId (previously filePath)
2728
const location = useLocation<{ reportId: string }>();
2829
const reportId = location.state?.reportId;
29-
const [isFetching, setIsFetching] = useState(false);
3030

3131
// Check the status of the report processing
3232
const checkReportStatus = async () => {
@@ -70,19 +70,21 @@ const ProcessingPage: React.FC = () => {
7070

7171
// Send the API request when component mounts
7272
useEffect(() => {
73+
// Use ref to ensure this effect runs only once for the core logic
74+
if (hasInitiatedProcessing.current) {
75+
return;
76+
}
77+
7378
if (!reportId) {
7479
setProcessingError('No report ID provided');
7580
setIsProcessing(false);
81+
hasInitiatedProcessing.current = true; // Mark as initiated even on error
7682
return;
7783
}
7884

79-
if (isFetching) {
80-
return;
81-
}
85+
hasInitiatedProcessing.current = true; // Mark as initiated before fetching
8286

8387
const processFile = async () => {
84-
setIsFetching(true);
85-
8688
try {
8789
// Send POST request to backend API
8890
const response = await axios.post(
@@ -93,8 +95,8 @@ const ProcessingPage: React.FC = () => {
9395

9496
console.log('File processing started:', response.data);
9597

96-
// Start checking the status every 5 seconds
97-
statusCheckIntervalRef.current = window.setInterval(checkReportStatus, 5000);
98+
// Start checking the status every 2 seconds
99+
statusCheckIntervalRef.current = window.setInterval(checkReportStatus, 2000);
98100

99101
// Run the first status check immediately
100102
checkReportStatus();
@@ -113,7 +115,8 @@ const ProcessingPage: React.FC = () => {
113115
window.clearInterval(statusCheckIntervalRef.current);
114116
}
115117
};
116-
}, [reportId, axios, history]);
118+
}, [reportId, location, history]);
119+
117120

118121
return (
119122
<IonPage className="processing-page">

0 commit comments

Comments
 (0)