Skip to content

Commit 38935c0

Browse files
committed
checkbox selection logic optimisation and bug fix where loading does not disappear if the file upload is cancelled
1 parent 12c2a99 commit 38935c0

File tree

2 files changed

+13
-8
lines changed

2 files changed

+13
-8
lines changed

src/features/diffViewer/components/uploadButton/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@ export default function UploadButton() {
1414

1515
const handleFileUpload = async (e: React.ChangeEvent<HTMLInputElement>) => {
1616
try {
17-
startLoading();
1817
const file = e.target.files?.[0];
1918
if (!file) {
2019
return;
2120
}
2221

22+
startLoading();
2323
const content = await file.text();
2424
const parsedPatch = parsePatch(content);
2525
setParsedDiffs(parsedPatch);

src/features/directoryTree/index.tsx

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import FolderIcon from "@mui/icons-material/Folder";
22
import FolderOpenIcon from "@mui/icons-material/FolderOpen";
33
import { Box, Button, useTheme } from "@mui/material";
44
import { RichTreeView } from "@mui/x-tree-view/RichTreeView";
5+
import type { StructuredPatch } from "diff";
56
import { useCallback, useEffect, useMemo, useState } from "react";
67

78
import { CustomTreeItem } from "@/components/styled/customTreeItem";
@@ -17,6 +18,15 @@ export default function DirectoryTree() {
1718
const [selectedItems, setSelectedItems] = useState<string[]>([]);
1819

1920
const patchFileInfos = useMemo(() => extractFileInfoFromPatches(parsedDiffs ?? []), [parsedDiffs]);
21+
const matchingStructuredPatches = useMemo(() => {
22+
const selectedItemsSet = new Set(selectedItems);
23+
return patchFileInfos.reduce((acc: StructuredPatch[], obj) => {
24+
if (selectedItemsSet.has(obj.actualFilePath)) {
25+
acc.push(obj.patch);
26+
}
27+
return acc;
28+
}, []);
29+
}, [patchFileInfos, selectedItems]);
2030

2131
const handleExpandClick = useCallback(() => {
2232
setExpandedItems((oldExpanded) => (oldExpanded.length === 0 ? getAllItemsWithChildrenItemIds(directoryData) : []));
@@ -34,13 +44,8 @@ export default function DirectoryTree() {
3444
* Update the visible patch files based on the selected items.
3545
*/
3646
useEffect(() => {
37-
const selectedItemsSet = new Set(selectedItems);
38-
const matchingPatches = patchFileInfos
39-
.filter((obj) => selectedItemsSet.has(obj.actualFilePath))
40-
.map((obj) => obj.patch);
41-
42-
setSelectedParsedDiffs(matchingPatches);
43-
}, [patchFileInfos, selectedItems, setSelectedParsedDiffs]);
47+
setSelectedParsedDiffs(matchingStructuredPatches);
48+
}, [matchingStructuredPatches, setSelectedParsedDiffs]);
4449

4550
/*
4651
* When the directory structure changes:

0 commit comments

Comments
 (0)