TagSpaces is an offline, open source, document manager with tagging support
fix openedEntries and watcher (#1997)
Stanimirf87e51f9a8fc
diff --git a/app/hooks/DirectoryContentContextProvider.tsx b/app/hooks/DirectoryContentContextProvider.tsxindex afe44adc1..6573a2928 100644--- a/app/hooks/DirectoryContentContextProvider.tsx+++ b/app/hooks/DirectoryContentContextProvider.tsx@@ -34,6 +34,7 @@ import {import { TS } from '-/tagspaces.namespace';import { useTranslation } from 'react-i18next';import {+ extractContainingDirectoryPath,extractFileName,extractFileExtension,extractTagsAsObjects,@@ -686,10 +687,20 @@ export const DirectoryContentContextProvider = ({const removeDirectoryEntries = useMemo(() => {return (entryPaths: string[]) => {- const entries = currentDirectoryEntries.filter(- entry => !entryPaths.includes(entry.path)- );- setCurrentDirectoryEntries(entries);+ if (entryPaths.some(ePath => ePath === currentDirectoryPath.current)) {+ //handle currentDirectoryPath deleted+ return openDirectory(+ extractContainingDirectoryPath(+ currentDirectoryPath.current,+ PlatformIO.getDirSeparator()+ )+ );+ } else {+ const entries = currentDirectoryEntries.filter(+ entry => !entryPaths.includes(entry.path)+ );+ setCurrentDirectoryEntries(entries);+ }};}, [currentDirectoryEntries]);diff --git a/app/hooks/FSWatcherContextProvider.tsx b/app/hooks/FSWatcherContextProvider.tsxindex b2692443a..1374daf0d 100644--- a/app/hooks/FSWatcherContextProvider.tsx+++ b/app/hooks/FSWatcherContextProvider.tsx@@ -71,6 +71,7 @@ export const FSWatcherContextProvider = ({const { currentLocation } = useCurrentLocationContext();const {loadDirectoryContent,+ currentDirectoryPath,currentDirectoryPerspective,addDirectoryEntries,removeDirectoryEntries@@ -98,7 +99,7 @@ export const FSWatcherContextProvider = ({useEffect(() => {watchForEvents();- }, [addDirectoryEntries, removeDirectoryEntries]);+ }, [addDirectoryEntries, removeDirectoryEntries, ignored.current]);function watchForEvents() {if (watcher !== undefined) {@@ -132,7 +133,10 @@ export const FSWatcherContextProvider = ({}const pathParts = path.split(PlatformIO.getDirSeparator());for (let i = 0; i < ignored.current.length; i++) {- if (path.startsWith(ignored[i]) || pathParts.includes(ignored[i])) {+ if (+ path.startsWith(ignored.current[i]) ||+ pathParts.includes(ignored.current[i])+ ) {// ignored.current.splice(i, 1);return;}@@ -155,7 +159,13 @@ export const FSWatcherContextProvider = ({case 'add':if (!path.includes(AppConfig.metaFolder)) {const entry = toFsEntry(path, true);- addDirectoryEntries([entry]);+ const dirPath = extractContainingDirectoryPath(+ path,+ PlatformIO.getDirSeparator()+ );+ if (currentDirectoryPath === dirPath) {+ addDirectoryEntries([entry]);+ }reflectCreateEntry(entry);dispatch(AppActions.reflectCreateEntry(path, true));}@@ -163,7 +173,13 @@ export const FSWatcherContextProvider = ({case 'addDir':if (!path.includes(AppConfig.metaFolder)) {const entry = toFsEntry(path, false);- addDirectoryEntries([entry]);+ const dirPath = extractContainingDirectoryPath(+ path,+ PlatformIO.getDirSeparator()+ );+ if (currentDirectoryPath === dirPath) {+ addDirectoryEntries([entry]);+ }reflectCreateEntry(entry);dispatch(AppActions.reflectCreateEntry(path, false));}@@ -234,8 +250,10 @@ export const FSWatcherContextProvider = ({function removeFromIgnored(path: string) {setTimeout(() => {for (let i = 0; i < ignored.current.length; i++) {- const pathParts = ignored[i].split(PlatformIO.getDirSeparator());- if (path.startsWith(ignored[i]) || pathParts.includes(path)) {+ const pathParts = ignored.current[i].split(+ PlatformIO.getDirSeparator()+ );+ if (path.startsWith(ignored.current[i]) || pathParts.includes(path)) {ignored.current.splice(i, 1);}}@@ -243,7 +261,7 @@ export const FSWatcherContextProvider = ({if (index > -1) {ignored.current.splice(index, 1);}*/- }, 1000);+ }, 2000);}function ignoreByWatcher(...paths) {diff --git a/app/hooks/FsActionsContextProvider.tsx b/app/hooks/FsActionsContextProvider.tsxindex b5c794bf4..c82563db6 100644--- a/app/hooks/FsActionsContextProvider.tsx+++ b/app/hooks/FsActionsContextProvider.tsx@@ -33,6 +33,7 @@ import { useNotificationContext } from '-/hooks/useNotificationContext';import { useLocationIndexContext } from '-/hooks/useLocationIndexContext';import { useSelectedEntriesContext } from '-/hooks/useSelectedEntriesContext';import { usePlatformFacadeContext } from '-/hooks/usePlatformFacadeContext';+import { useFSWatcherContext } from '-/hooks/useFSWatcherContext';type FsActionsContextData = {renameDirectory: (@@ -62,6 +63,7 @@ export const FsActionsContextProvider = ({const { openDirectory, currentDirectoryPath } = useDirectoryContentContext();const { reflectRenameEntry } = useLocationIndexContext();const { showNotification } = useNotificationContext();+ const { watcher } = useFSWatcherContext();const {renameFilePromise,renameFilesPromise,@@ -201,7 +203,7 @@ export const FsActionsContextProvider = ({renameFile,openFileNatively};- }, [openedEntries]);+ }, [openedEntries, watcher]);return (<FsActionsContext.Provider value={context}>diff --git a/app/hooks/IOActionsContextProvider.tsx b/app/hooks/IOActionsContextProvider.tsxindex b563c230c..653c655d4 100644--- a/app/hooks/IOActionsContextProvider.tsx+++ b/app/hooks/IOActionsContextProvider.tsx@@ -148,11 +148,7 @@ export const IOActionsContextProvider = ({deleteFilePromise,deleteDirectoryPromise} = usePlatformFacadeContext();- const {- openedEntries,- reflectDeleteDirectory,- reflectDeleteFile- } = useOpenedEntryContext();+ const { reflectDeleteDirectory, reflectDeleteFile } = useOpenedEntryContext();const {currentDirectoryEntries,currentDirectoryPath,@@ -270,7 +266,7 @@ export const IOActionsContextProvider = ({return false;});};- }, [currentDirectoryEntries]);+ }, [currentDirectoryEntries, reflectDeleteFile, reflectDeleteDirectory]);const deleteDirectory = useMemo(() => {return (directoryPath: string, reflect = true) =>@@ -321,7 +317,7 @@ export const IOActionsContextProvider = ({return false;// dispatch stopLoadingAnimation});- }, [currentDirectoryEntries, useTrashCan]);+ }, [currentDirectoryEntries, useTrashCan, reflectDeleteDirectory]);const deleteFile = useMemo(() => {return (filePath: string, uuid: string, reflect = true) =>@@ -387,7 +383,7 @@ export const IOActionsContextProvider = ({);return false;});- }, [currentDirectoryEntries, useTrashCan]);+ }, [currentDirectoryEntries, useTrashCan, reflectDeleteFile]);function moveDirs(dirPaths: Array<any>,@@ -1007,7 +1003,7 @@ export const IOActionsContextProvider = ({uploadFilesAPI,uploadFiles};- }, [currentDirectoryEntries, openedEntries]);+ }, [createDirectory, deleteEntries, deleteDirectory, deleteFile]);return (<IOActionsContext.Provider value={context}>diff --git a/app/hooks/OpenedEntryContextProvider.tsx b/app/hooks/OpenedEntryContextProvider.tsxindex dfefc0fe3..9e6e7654c 100644--- a/app/hooks/OpenedEntryContextProvider.tsx+++ b/app/hooks/OpenedEntryContextProvider.tsx@@ -955,31 +955,35 @@ export const OpenedEntryContextProvider = ({}}- function reflectDeleteDirectory(directoryPath) {- if (- openedEntries &&- openedEntries.length > 0 &&- openedEntries.some(- file =>- extractContainingDirectoryPath(- file.path,- PlatformIO.getDirSeparator()- ) === directoryPath- )- ) {- closeAllFiles();- }- }+ const reflectDeleteDirectory = useMemo(() => {+ return (directoryPath: string) => {+ if (+ openedEntries &&+ openedEntries.length > 0 &&+ openedEntries.some(+ file => file.path.startsWith(directoryPath)+ /*extractContainingDirectoryPath(+ file.path,+ PlatformIO.getDirSeparator()+ ) === directoryPath */+ )+ ) {+ closeAllFiles();+ }+ };+ }, [openedEntries]);- function reflectDeleteFile(filePath) {- if (- openedEntries &&- openedEntries.length > 0 &&- openedEntries.some(file => file.path === filePath)- ) {- closeAllFiles();- }- }+ const reflectDeleteFile = useMemo(() => {+ return (filePath: string) => {+ if (+ openedEntries &&+ openedEntries.length > 0 &&+ openedEntries.some(file => file.path === filePath)+ ) {+ closeAllFiles();+ }+ };+ }, [openedEntries]);const context = useMemo(() => {return {diff --git a/app/hooks/PlatformFacadeContextProvider.tsx b/app/hooks/PlatformFacadeContextProvider.tsxindex 3985587c2..0710f6c99 100644--- a/app/hooks/PlatformFacadeContextProvider.tsx+++ b/app/hooks/PlatformFacadeContextProvider.tsx@@ -120,7 +120,12 @@ export type PlatformFacadeContextProviderProps = {export const PlatformFacadeContextProvider = ({children}: PlatformFacadeContextProviderProps) => {- const { ignoreByWatcher, deignoreByWatcher, ignored } = useFSWatcherContext();+ const {+ ignoreByWatcher,+ deignoreByWatcher,+ ignored,+ watcher+ } = useFSWatcherContext();const { t } = useTranslation();const dispatch: AppDispatch = useDispatch();@@ -488,7 +493,7 @@ export const PlatformFacadeContextProvider = ({deleteDirectoryPromise,setFolderThumbnailPromise};- }, [ignored]);+ }, [watcher, ignored]);return (<PlatformFacadeContext.Provider value={context}>