@@ -25,7 +25,7 @@ const ProcessingPage: React.FC = () => {
2525 const [ isProcessing , setIsProcessing ] = useState ( true ) ;
2626 const [ processingError , setProcessingError ] = useState < string | null > ( null ) ;
2727 const statusCheckIntervalRef = useRef < number | null > ( null ) ;
28- const hasInitiatedProcessing = useRef ( false ) ;
28+ const lastTriggeredTime = useRef < number | null > ( null ) ;
2929
3030 // Get the location state which may contain the reportId (previously filePath)
3131 const location = useLocation < { reportId : string } > ( ) ;
@@ -98,28 +98,26 @@ const ProcessingPage: React.FC = () => {
9898 } ;
9999
100100 // Handle retry attempt
101- const handleRetry = ( ) => {
101+ const execute = ( ) => {
102102 // Reset error state and try processing the same file again
103103 setProcessingError ( null ) ;
104104 setIsProcessing ( true ) ;
105- hasInitiatedProcessing . current = false ;
105+ lastTriggeredTime . current = Date . now ( ) ;
106106 processFile ( ) ;
107107 } ;
108108
109109 // Send the API request when component mounts
110110 useEffect ( ( ) => {
111- // Use ref to ensure this effect runs only once for the core logic
112- if ( hasInitiatedProcessing . current ) {
111+ // check last triggered time to prevent multiple calls, if it's within 100ms then ignore
112+ if ( ( lastTriggeredTime . current && lastTriggeredTime . current > Date . now ( ) - 100 ) || ! reportId ) {
113113 return ;
114114 }
115115
116- hasInitiatedProcessing . current = true ; // Mark as initiated before fetching
117-
118- processFile ( ) ;
116+ execute ( ) ;
119117
120118 // Clean up the interval when the component unmounts
121119 return clearStatusCheckInterval ;
122- } , [ reportId , location , history ] ) ;
120+ } , [ reportId , location . pathname , history ] ) ;
123121
124122 return (
125123 < IonPage className = "processing-page" >
@@ -141,9 +139,7 @@ const ProcessingPage: React.FC = () => {
141139 { isProcessing && < ProcessingAnimation firstName = { firstName } /> }
142140
143141 { /* Error state - shows when processing fails */ }
144- { processingError && (
145- < ProcessingError errorMessage = { processingError } onRetry = { handleRetry } />
146- ) }
142+ { processingError && < ProcessingError errorMessage = { processingError } onRetry = { execute } /> }
147143 </ div >
148144 </ IonContent >
149145 </ IonPage >
0 commit comments