Skip to content

Commit f17f5a4

Browse files
authored
Merge pull request #95 from ModusCreateOrg/ADE-66
Refactor ProcessingPage component and update package-lock.json to include Prettier
2 parents 8d619f9 + 0bf7006 commit f17f5a4

File tree

2 files changed

+26
-13
lines changed

2 files changed

+26
-13
lines changed

frontend/src/pages/Processing/ProcessingPage.tsx

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -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>

package-lock.json

Lines changed: 18 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)