Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 8 additions & 12 deletions frontend/src/pages/Processing/ProcessingPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const ProcessingPage: React.FC = () => {
const [isProcessing, setIsProcessing] = useState(true);
const [processingError, setProcessingError] = useState<string | null>(null);
const statusCheckIntervalRef = useRef<number | null>(null);
const hasInitiatedProcessing = useRef(false);
const lastTriggeredTime = useRef<number | null>(null);

// Get the location state which may contain the reportId (previously filePath)
const location = useLocation<{ reportId: string }>();
Expand Down Expand Up @@ -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 (
<IonPage className="processing-page">
Expand All @@ -141,9 +139,7 @@ const ProcessingPage: React.FC = () => {
{isProcessing && <ProcessingAnimation firstName={firstName} />}

{/* Error state - shows when processing fails */}
{processingError && (
<ProcessingError errorMessage={processingError} onRetry={handleRetry} />
)}
{processingError && <ProcessingError errorMessage={processingError} onRetry={execute} />}
</div>
</IonContent>
</IonPage>
Expand Down
19 changes: 18 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.