Skip to content

Commit 3f1b99c

Browse files
fix: handle navigation when all files are harmful content
When all uploaded files contain harmful content, the backend processes them very fast (before WebSocket connects), causing the UI to get stuck loading indefinitely. This fix: - Detects already-completed batches on initial fetch and navigates directly - Checks both batch status and individual file terminal states - Adds navigation guard (useRef) to prevent duplicate navigations - Prevents resetting allFilesCompleted state after it's been finalized Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent e9891d7 commit 3f1b99c

1 file changed

Lines changed: 23 additions & 6 deletions

File tree

src/frontend/src/pages/modernizationPage.tsx

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ import { Light as SyntaxHighlighter } from "react-syntax-highlighter"
3131
import { vs } from "react-syntax-highlighter/dist/esm/styles/hljs"
3232
import sql from "react-syntax-highlighter/dist/cjs/languages/hljs/sql"
3333
import { useNavigate, useParams } from "react-router-dom"
34-
import { useState, useEffect, useCallback } from "react"
34+
import { useState, useEffect, useCallback, useRef } from "react"
3535
import { getApiUrl, headerBuilder } from '../api/config';
3636
import BatchHistoryPanel from "../components/batchHistoryPanel"
3737
import PanelRight from "../components/Panels/PanelRight";
@@ -501,6 +501,7 @@ const ModernizationPage = () => {
501501
const [isZipButtonDisabled, setIsZipButtonDisabled] = useState(true);
502502
const [fileLoading, setFileLoading] = useState(false);
503503
const [lastActivityTime, setLastActivityTime] = useState<number>(Date.now());
504+
const hasNavigatedRef = useRef(false);
504505
//const [pageLoadTime] = useState<number>(Date.now());
505506

506507
// Fetch file content when a file is selected
@@ -536,12 +537,22 @@ const ModernizationPage = () => {
536537
setBatchSummary(data);
537538
if (data) {
538539

539-
const batchCompleted = data.status?.toLowerCase() === "completed" || data.status === "failed";
540-
if (batchCompleted) {
540+
const batchCompleted = data.status?.toLowerCase() === "completed" || data.status?.toLowerCase() === "failed";
541+
const allFilesTerminal = data.files.every((file: any) =>
542+
["completed", "failed", "error"].includes(file.status?.toLowerCase() || "")
543+
);
544+
545+
if (batchCompleted || allFilesTerminal) {
541546
setAllFilesCompleted(true);
542547
if (data.hasFiles > 0) {
543548
setIsZipButtonDisabled(false);
544549
}
550+
// Batch already finished (e.g., all files were harmful content) — navigate directly
551+
if (!hasNavigatedRef.current) {
552+
hasNavigatedRef.current = true;
553+
navigate(`/batch-view/${batchId}`);
554+
return;
555+
}
545556
}
546557
// Transform the server response to an array of your FileItem objects
547558
const fileItems: FileItem[] = data.files.map((file: any, index: number) => ({
@@ -725,7 +736,10 @@ const ModernizationPage = () => {
725736
// Update files state when Redux fileList changes
726737
useEffect(() => {
727738
if (reduxFileList && reduxFileList.length > 0) {
728-
setAllFilesCompleted(false);
739+
// Only reset completion state if not already finalized
740+
if (!allFilesCompleted) {
741+
setAllFilesCompleted(false);
742+
}
729743
// Map the Redux fileList to our FileItem format
730744
const fileItems: FileItem[] = reduxFileList.filter(file => file.type !== 'summary').map((file: any, index: number) => ({
731745

@@ -832,8 +846,11 @@ const ModernizationPage = () => {
832846
});
833847

834848
// Navigate only after all files have reached terminal states.
835-
console.log("Processing complete (all files done), navigating to batch view page");
836-
navigate(`/batch-view/${batchId}`);
849+
if (!hasNavigatedRef.current) {
850+
hasNavigatedRef.current = true;
851+
console.log("Processing complete (all files done), navigating to batch view page");
852+
navigate(`/batch-view/${batchId}`);
853+
}
837854
}
838855
} catch (err) {
839856
console.error("Failed to update summary status:", err);

0 commit comments

Comments
 (0)