Skip to content

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

TSN492 fix issue by switching folder from different locations (#1230)

Stanimir900ce2def232
diff --git a/app/components/FolderContainer.tsx b/app/components/FolderContainer.tsx
index 0ba303733..bfab839f3 100644
--- a/app/components/FolderContainer.tsx
+++ b/app/components/FolderContainer.tsx
@@ -56,6 +56,8 @@ import {
FileSystemEntry,
FileSystemEntryMeta
} from '-/services/utils-io';
+import { getLocations, Location } from '-/reducers/locations';
+import AppConfig from '-/config';
const GridPerspective = React.lazy(() =>
import(
@@ -225,9 +227,11 @@ interface Props {
maxSearchResults: number;
currentDirectoryPerspective: string;
currentLocationPath: string;
+ locations: Array<Location>;
openedFiles: Array<OpenedEntry>;
updateCurrentDirEntry: (path: string, entry: Object) => void;
setCurrentDirectoryColor: (color: string) => void;
+ setCurrentLocationId: (uuid: string) => void;
}
const FolderContainer = (props: Props) => {
@@ -279,6 +283,14 @@ const FolderContainer = (props: Props) => {
// console.log('Current path : ' + normalizedCurrentPath);
// console.log('Current location path : ' + normalizedCurrentLocationPath);
+ if (!normalizedCurrentPath.startsWith(normalizedCurrentLocationPath)) {
+ const location = getLocation(props.currentDirectoryPath);
+ if (location !== undefined) {
+ props.setCurrentLocationId(location.uuid); // TODO rethink this maybe its not the right place here
+ normalizedCurrentLocationPath =
+ addSlash + normalizePath(location.paths[0].split('\\').join('/'));
+ }
+ }
while (
normalizedCurrentPath.lastIndexOf('/') > 0 &&
normalizedCurrentPath.startsWith(normalizedCurrentLocationPath)
@@ -293,6 +305,17 @@ const FolderContainer = (props: Props) => {
normalizedCurrentPath.lastIndexOf('/')
);
}
+
+ // diff Location
+ /* const currentPathArray = normalizedCurrentPath.split('/');
+ const currentLocationPathArray = normalizedCurrentLocationPath.split('/');
+ for (let i = 0; i < currentPathArray.length; i += 1) {
+ if (currentPathArray[i] !== currentLocationPathArray[i]) {
+
+ pathParts.push(currentPathArray[i]);
+ }
+ } */
+
// console.log('Path parts : ' + JSON.stringify(pathParts));
if (pathParts.length >= 1) {
pathParts = pathParts.slice(1, pathParts.length); // remove current directory
@@ -303,6 +326,15 @@ const FolderContainer = (props: Props) => {
}
}
+ function getLocation(directoryPath) {
+ for (let i = 0; i < props.locations.length; i += 1) {
+ if (directoryPath.startsWith(props.locations[i].paths[0])) {
+ return props.locations[i];
+ }
+ }
+ return undefined;
+ }
+
const openDirectoryMenu = (event: React.MouseEvent<HTMLButtonElement>) => {
setDirectoryContextMenuAnchorEl(event.currentTarget);
// setDirectoryContextMenuOpened(true);
@@ -577,6 +609,7 @@ function mapStateToProps(state) {
currentDirectoryPerspective: getCurrentDirectoryPerspective(state),
searchResultCount: getSearchResultCount(state),
currentLocationPath: getCurrentLocationPath(state),
+ locations: getLocations(state),
maxSearchResults: getMaxSearchResults(state),
isDesktopMode: getDesktopMode(state),
isReadOnlyMode: isReadOnlyMode(state)
@@ -608,7 +641,8 @@ function mapActionCreatorsToProps(dispatch) {
openSearchPanel: AppActions.openSearchPanel,
setCurrentDirectoryPerspective: AppActions.setCurrentDirectoryPerspective,
updateCurrentDirEntry: AppActions.updateCurrentDirEntry,
- setCurrentDirectoryColor: AppActions.setCurrentDirectoryColor
+ setCurrentDirectoryColor: AppActions.setCurrentDirectoryColor,
+ setCurrentLocationId: AppActions.setCurrentLocationId
},
dispatch
);