diff --git a/frontend/src/pages/Processing/ProcessingPage.tsx b/frontend/src/pages/Processing/ProcessingPage.tsx index d4a8a2dc..da28b02b 100644 --- a/frontend/src/pages/Processing/ProcessingPage.tsx +++ b/frontend/src/pages/Processing/ProcessingPage.tsx @@ -25,7 +25,7 @@ const ProcessingPage: React.FC = () => { const [isProcessing, setIsProcessing] = useState(true); const [processingError, setProcessingError] = useState(null); const statusCheckIntervalRef = useRef(null); - const hasInitiatedProcessing = useRef(false); + const lastTriggeredTime = useRef(null); // Get the location state which may contain the reportId (previously filePath) const location = useLocation<{ reportId: string }>(); @@ -98,28 +98,26 @@ const ProcessingPage: React.FC = () => { }; // Handle retry attempt - const handleRetry = () => { + const execute = () => { // Reset error state and try processing the same file again setProcessingError(null); setIsProcessing(true); - hasInitiatedProcessing.current = false; + lastTriggeredTime.current = Date.now(); processFile(); }; // Send the API request when component mounts useEffect(() => { - // Use ref to ensure this effect runs only once for the core logic - if (hasInitiatedProcessing.current) { + // check last triggered time to prevent multiple calls, if it's within 100ms then ignore + if ((lastTriggeredTime.current && lastTriggeredTime.current > Date.now() - 100) || !reportId) { return; } - hasInitiatedProcessing.current = true; // Mark as initiated before fetching - - processFile(); + execute(); // Clean up the interval when the component unmounts return clearStatusCheckInterval; - }, [reportId, location, history]); + }, [reportId, location.pathname, history]); return ( @@ -141,9 +139,7 @@ const ProcessingPage: React.FC = () => { {isProcessing && } {/* Error state - shows when processing fails */} - {processingError && ( - - )} + {processingError && } diff --git a/package-lock.json b/package-lock.json index ed3b8e68..fe70bca2 100644 --- a/package-lock.json +++ b/package-lock.json @@ -6,7 +6,8 @@ "": { "name": "medical-reports-explainer", "devDependencies": { - "husky": "^9.1.7" + "husky": "^9.1.7", + "prettier": "^3.0.0" } }, "node_modules/husky": { @@ -24,6 +25,22 @@ "funding": { "url": "https://github.com/sponsors/typicode" } + }, + "node_modules/prettier": { + "version": "3.5.3", + "resolved": "https://registry.npmjs.org/prettier/-/prettier-3.5.3.tgz", + "integrity": "sha512-QQtaxnoDJeAkDvDKWCLiwIXkTgRhwYDEQCghU9Z6q03iyek/rxRh/2lC3HB7P8sWT2xC/y5JDctPLBIGzHKbhw==", + "dev": true, + "license": "MIT", + "bin": { + "prettier": "bin/prettier.cjs" + }, + "engines": { + "node": ">=14" + }, + "funding": { + "url": "https://github.com/prettier/prettier?sponsor=1" + } } } }