fix: File manager rerenders (#7999)
* Fix infinite rerender issue * [autofix.ci] apply automated fixes --------- Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
This commit is contained in:
parent
b277058f0d
commit
f9b9598599
1 changed files with 19 additions and 17 deletions
|
|
@ -20,11 +20,24 @@ export default function RecentFilesComponent({
|
|||
types: string[];
|
||||
isList: boolean;
|
||||
}) {
|
||||
const filesWithType = files.map((file) => ({
|
||||
...file,
|
||||
type: file.path.split(".").pop()?.toLowerCase(),
|
||||
}));
|
||||
const [fuse, setFuse] = useState<Fuse<FileType>>(new Fuse([]));
|
||||
const filesWithType = useMemo(
|
||||
() =>
|
||||
files.map((file) => ({
|
||||
...file,
|
||||
type: file.path.split(".").pop()?.toLowerCase(),
|
||||
})),
|
||||
[files],
|
||||
);
|
||||
|
||||
const fuse = useMemo(
|
||||
() =>
|
||||
new Fuse(filesWithType, {
|
||||
keys: ["name", "type"],
|
||||
threshold: 0.3,
|
||||
}),
|
||||
[filesWithType],
|
||||
);
|
||||
|
||||
const [searchQuery, setSearchQuery] = useState("");
|
||||
|
||||
const { mutate: renameFile } = usePostRenameFileV2();
|
||||
|
|
@ -39,18 +52,7 @@ export default function RecentFilesComponent({
|
|||
return fileExtension && (!types || types.includes(fileExtension));
|
||||
});
|
||||
return filteredFiles;
|
||||
}, [searchQuery, filesWithType, selectedFiles, types]);
|
||||
|
||||
useEffect(() => {
|
||||
if (filesWithType) {
|
||||
setFuse(
|
||||
new Fuse(filesWithType, {
|
||||
keys: ["name", "type"],
|
||||
threshold: 0.3,
|
||||
}),
|
||||
);
|
||||
}
|
||||
}, [filesWithType]);
|
||||
}, [searchQuery, filesWithType, types]);
|
||||
|
||||
const handleFileSelect = (filePath: string) => {
|
||||
setSelectedFiles(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue