Skip to content

TagSpaces is an offline, open source, document manager with tagging support

Unable to navigate to parent folder if it is not in current location (#2337)

Stanimir4e9bc6eb3245
diff --git a/src/renderer/hooks/CurrentLocationContextProvider.tsx b/src/renderer/hooks/CurrentLocationContextProvider.tsx
index b81efe2b1..f13356540 100644
--- a/src/renderer/hooks/CurrentLocationContextProvider.tsx
+++ b/src/renderer/hooks/CurrentLocationContextProvider.tsx
@@ -18,7 +18,6 @@
import React, {
createContext,
- useCallback,
useEffect,
useMemo,
useReducer,
@@ -283,6 +282,22 @@ export const CurrentLocationContextProvider = ({
(l) => l.uuid === currentLocationId.current,
);
}
+
+ /*async function findLocationFromPath(
+ path: string,
+ ): Promise<CommonLocation | undefined> {
+ if (!path) return undefined;
+
+ for (const loc of allLocations.current) {
+ const resolved = await resolveRelativePath(loc.path);
+ if (path.startsWith(resolved)) {
+ return loc;
+ }
+ }
+
+ return undefined;
+ }*/
+
function getDirSeparator(locationID: string = undefined): string {
const loc = findLocation(locationID);
if (loc) {
diff --git a/src/renderer/hooks/DirectoryContentContextProvider.tsx b/src/renderer/hooks/DirectoryContentContextProvider.tsx
index c6a108e97..eb22aa631 100644
--- a/src/renderer/hooks/DirectoryContentContextProvider.tsx
+++ b/src/renderer/hooks/DirectoryContentContextProvider.tsx
@@ -178,7 +178,7 @@ export const DirectoryContentContext =
//removeDirectoryEntries: undefined,
//reflectRenameEntries: undefined,
setSearchQuery: () => {},
- loadParentDirectoryContent: () => {},
+ loadParentDirectoryContent: undefined,
loadDirectoryContent: undefined,
enhanceDirectoryContent: undefined,
openDirectory: undefined,
@@ -708,32 +708,24 @@ export const DirectoryContentContextProvider = ({
return openCurrentDirectory();
}
- // dispatch(actions.setIsLoading(true));
-
if (currentDirectory.current !== undefined) {
- const parentDirectory = extractParentDirectoryPath(
- currentDirectory.current.path,
- currentLocation?.getDirSeparator(),
- );
- console.log(
- 'parentDirectory: ' +
- parentDirectory +
- ' - currentLocationPath: ' +
- currentLocationPath.current,
- );
- if (
- parentDirectory.includes(
- cleanTrailingDirSeparator(currentLocationPath.current),
- )
- ) {
- openDirectory(parentDirectory);
- } else {
- showNotification(t('core:parentDirNotInLocation'), 'warning', true);
- // dispatch(actions.setIsLoading(false));
+ const loc = findLocation(currentDirectory.current.locationID);
+
+ if (loc) {
+ const parentDirectory = extractParentDirectoryPath(
+ currentDirectory.current.path,
+ );
+ if (
+ !loc.path ||
+ parentDirectory.includes(cleanTrailingDirSeparator(loc.path))
+ ) {
+ return openDirectory(parentDirectory, undefined, loc);
+ } else {
+ showNotification(t('core:parentDirNotInLocation'), 'warning', true);
+ }
}
} else {
showNotification(t('core:firstOpenaFolder'), 'warning', true);
- // dispatch(actions.setIsLoading(false));
}
}