TagSpaces is an offline, open source, document manager with tagging support
fix duplicate dir in watcher (#2027)
Stanimir9a1154de19d2
diff --git a/src/renderer/hooks/DirectoryContentContextProvider.tsx b/src/renderer/hooks/DirectoryContentContextProvider.tsxindex 2682dcb2b..16712a537 100644--- a/src/renderer/hooks/DirectoryContentContextProvider.tsx+++ b/src/renderer/hooks/DirectoryContentContextProvider.tsx@@ -791,10 +791,17 @@ export const DirectoryContentContextProvider = ({),);} else {- const entries = currentDirectoryEntries.filter(- (entry) => !entryPaths.includes(entry.path),+ const index = currentDirectoryEntries.findIndex((entry) =>+ entryPaths.includes(entry.path),);- setCurrentDirectoryEntries(entries);+ if (index > -1) {+ // delete in place (for fs watcher events unlink/add in 20ms)+ currentDirectoryEntries.splice(index, 1);+ /*const entries = currentDirectoryEntries.filter(+ (entry) => !entryPaths.includes(entry.path),+ );*/+ setCurrentDirectoryEntries([...currentDirectoryEntries]); //entries);+ }}};}, [currentDirectoryEntries]);diff --git a/src/renderer/hooks/FSWatcherContextProvider.tsx b/src/renderer/hooks/FSWatcherContextProvider.tsxindex 867a37df4..dda84d740 100644--- a/src/renderer/hooks/FSWatcherContextProvider.tsx+++ b/src/renderer/hooks/FSWatcherContextProvider.tsx@@ -64,6 +64,7 @@ export const FSWatcherContextProvider = ({}: FSWatcherContextProviderProps) => {const { currentLocation } = useCurrentLocationContext();const {+ currentDirectoryEntries,loadDirectoryContent,currentDirectoryPath,currentLocationPath,@@ -142,10 +143,13 @@ export const FSWatcherContextProvider = ({switch (event) {case 'unlink':case 'unlinkDir':- if (!path.includes(AppConfig.metaFolder)) {+ if (+ //currentDirectoryEntries.some((entry) => path === entry.path) &&+ !path.includes(AppConfig.metaFolder)+ ) {removeDirectoryEntries([path]);reflectDeleteEntry(path);- dispatch(AppActions.reflectDeleteEntry(path));+ //dispatch(AppActions.reflectDeleteEntry(path));}break;case 'add':@@ -159,7 +163,7 @@ export const FSWatcherContextProvider = ({addDirectoryEntries([entry]);}reflectCreateEntry(entry);- dispatch(AppActions.reflectCreateEntry(path, true));+ //dispatch(AppActions.reflectCreateEntry(path, true));}break;case 'addDir':@@ -173,7 +177,7 @@ export const FSWatcherContextProvider = ({addDirectoryEntries([entry]);}reflectCreateEntry(entry);- dispatch(AppActions.reflectCreateEntry(path, false));+ //dispatch(AppActions.reflectCreateEntry(path, false));}break;case 'change':@@ -220,7 +224,12 @@ export const FSWatcherContextProvider = ({break;}};- }, [addDirectoryEntries, removeDirectoryEntries, ignored.current]);+ }, [+ currentDirectoryEntries,+ addDirectoryEntries,+ removeDirectoryEntries,+ ignored.current,+ ]);useEffect(() => {if (AppConfig.isElectron) {