@@ -2,6 +2,7 @@ import FolderIcon from "@mui/icons-material/Folder";
22import FolderOpenIcon from "@mui/icons-material/FolderOpen" ;
33import { Box , Button , useTheme } from "@mui/material" ;
44import { RichTreeView } from "@mui/x-tree-view/RichTreeView" ;
5+ import type { StructuredPatch } from "diff" ;
56import { useCallback , useEffect , useMemo , useState } from "react" ;
67
78import { 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