Skip to content

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

TSN499 fix issues by switching dirs and location local and on s3( #1243)

Stanimir032dbd0d4cf2
diff --git a/app/components/FolderContainer.tsx b/app/components/FolderContainer.tsx
index 911391880..637fa10dc 100644
--- a/app/components/FolderContainer.tsx
+++ b/app/components/FolderContainer.tsx
@@ -35,7 +35,7 @@ import {
getMaxSearchResults,
getDesktopMode
} from '-/reducers/settings';
-import { locationType, getLocations, Location } from '-/reducers/locations';
+import { getLocations, Location } from '-/reducers/locations';
import {
actions as AppActions,
getDirectoryContent,
@@ -161,7 +161,6 @@ const styles: any = (theme: any) => ({
topPanel: {
height: 50,
width: '100%',
- // overflowX: 'overlay',
backgroundColor: theme.palette.background.default
},
centerPanel: {
@@ -176,8 +175,6 @@ const styles: any = (theme: any) => ({
},
folderButton: {
minWidth: 30,
- // whiteSpace: 'nowrap',
- // overflow: 'hidden',
paddingLeft: 3,
paddingRight: 3,
lineHeight: '17px',
@@ -230,7 +227,6 @@ interface Props {
openedFiles: Array<OpenedEntry>;
updateCurrentDirEntry: (path: string, entry: Object) => void;
setCurrentDirectoryColor: (color: string) => void;
- setCurrentLocationId: (uuid: string) => void;
}
const FolderContainer = (props: Props) => {
@@ -279,17 +275,7 @@ const FolderContainer = (props: Props) => {
addSlash +
normalizePath(props.currentLocationPath.split('\\').join('/'));
}
- // console.log('Current path : ' + normalizedCurrentPath);
- // console.log('Current location path : ' + normalizedCurrentLocationPath);
- if (!normalizedCurrentPath.startsWith(normalizedCurrentLocationPath)) {
- const location = getLocation(props.currentDirectoryPath);
- if (location !== undefined && location.type === locationType.TYPE_LOCAL) {
- 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)
@@ -305,16 +291,6 @@ const FolderContainer = (props: Props) => {
);
}
- // 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
@@ -325,15 +301,6 @@ 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);
@@ -638,8 +605,8 @@ function mapActionCreatorsToProps(dispatch) {
openSearchPanel: AppActions.openSearchPanel,
setCurrentDirectoryPerspective: AppActions.setCurrentDirectoryPerspective,
updateCurrentDirEntry: AppActions.updateCurrentDirEntry,
- setCurrentDirectoryColor: AppActions.setCurrentDirectoryColor,
- setCurrentLocationId: AppActions.setCurrentLocationId
+ setCurrentDirectoryColor: AppActions.setCurrentDirectoryColor
+ // changeLocation: AppActions.changeLocation
},
dispatch
);
diff --git a/app/components/MobileNavigation.tsx b/app/components/MobileNavigation.tsx
index 118fa7091..c85f3f53a 100644
--- a/app/components/MobileNavigation.tsx
+++ b/app/components/MobileNavigation.tsx
@@ -144,11 +144,7 @@ class MobileNavigation extends React.Component<Props, State> {
}}
/>
{isTagLibraryPanelOpened && <TagLibrary />}
- <Search
- isSearchPanelOpened={isSearchPanelOpened}
- hideDrawer={hideDrawer}
- style={{ display: isSearchPanelOpened ? 'block' : 'none' }}
- />
+ {isSearchPanelOpened && <Search hideDrawer={hideDrawer} />}
{/* {isPerspectivesPanelOpened && <PerspectiveManager />} */}
{isHelpFeedbackPanelOpened && (
<HelpFeedbackPanel
diff --git a/app/components/Search.tsx b/app/components/Search.tsx
index 8ead048ab..fd8871aae 100644
--- a/app/components/Search.tsx
+++ b/app/components/Search.tsx
@@ -73,7 +73,7 @@ import PlatformIO from '../services/platform-io';
interface Props {
classes: any;
- style: any;
+ style?: any;
searchLocationIndex: (searchQuery: SearchQuery) => void;
createLocationsIndexes: () => void;
searchAllLocations: (searchQuery: SearchQuery) => void;
@@ -87,7 +87,6 @@ interface Props {
indexedEntriesCount: number;
maxSearchResults: number;
indexing: boolean;
- isSearchPanelOpened: boolean;
}
const Search = React.memo((props: Props) => {
@@ -120,7 +119,7 @@ const Search = React.memo((props: Props) => {
useEffect(() => {
focusMainSearchFiled();
- }, [props.isSearchPanelOpened]);
+ }, []);
const focusMainSearchFiled = () => {
if (mainSearchField) {
diff --git a/app/components/VerticalNavigation.tsx b/app/components/VerticalNavigation.tsx
index 28f80019d..764bf6baa 100644
--- a/app/components/VerticalNavigation.tsx
+++ b/app/components/VerticalNavigation.tsx
@@ -398,10 +398,7 @@ class VerticalNavigation extends React.Component<Props, State> {
}}
/>
{isTagLibraryPanelOpened && <TagLibrary />}
- <Search
- isSearchPanelOpened={isSearchPanelOpened}
- style={{ display: isSearchPanelOpened ? 'block' : 'none' }}
- />
+ {isSearchPanelOpened && <Search />}
{isHelpFeedbackPanelOpened && (
<HelpFeedbackPanel
openFileNatively={openFileNatively}
diff --git a/app/reducers/app.ts b/app/reducers/app.ts
index 4aa6f5de1..f4553ec7b 100644
--- a/app/reducers/app.ts
+++ b/app/reducers/app.ts
@@ -38,7 +38,8 @@ import {
getThumbFileLocationForFile,
extractParentDirectoryPath,
extractTagsAsObjects,
- normalizePath
+ normalizePath,
+ extractLocation
} from '-/utils/paths';
import { formatDateTime4Tag, getURLParameter } from '-/utils/misc';
import i18n from '../services/i18n';
@@ -894,12 +895,16 @@ export const actions = {
getState: () => any
) => {
console.time('listDirectoryPromise');
- const { settings } = getState();
+ const { settings, locations } = getState();
window.walkCanceled = false;
function loadDirectoryContentInt(fsEntryMeta?: FileSystemEntryMeta) {
// Uncomment the following line will to clear all content before loading new dir content
dispatch(actions.loadDirectorySuccessInt(directoryPath, [], true)); // this is to reset directoryContent (it will reset color too)
+ const location = extractLocation(directoryPath, locations);
+ if (location !== undefined) {
+ dispatch(actions.changeLocation(location));
+ }
// dispatch(actions.setCurrentDirectoryColor('')); // this is to reset color only
dispatch(actions.showNotification(i18n.t('core:loading'), 'info', false));
PlatformIO.listDirectoryPromise(directoryPath, false)
@@ -1241,6 +1246,16 @@ export const actions = {
type: types.SET_CURRENLOCATIONID,
locationId
}),
+ changeLocation: (location: Location) => (
+ dispatch: (actions: Object) => void,
+ getState: () => any
+ ) => {
+ const { currentLocationId } = getState().app;
+ if (location.uuid !== currentLocationId) {
+ dispatch(LocationIndexActions.clearDirectoryIndex());
+ dispatch(actions.setCurrentLocationId(location.uuid));
+ }
+ },
openLocationById: (locationId: string) => (
dispatch: (actions: Object) => void,
getState: () => any
@@ -1254,13 +1269,11 @@ export const actions = {
});
},
openLocation: (location: Location) => (
- dispatch: (actions: Object) => void,
- getState: () => any
+ dispatch: (actions: Object) => void
) => {
if (Pro && Pro.Watcher) {
Pro.Watcher.stopWatching();
}
- const { currentLocationId } = getState().app;
if (location.type === locationType.TYPE_CLOUD) {
PlatformIO.enableObjectStoreSupport(location)
.then(() => {
@@ -1272,10 +1285,7 @@ export const actions = {
)
);
dispatch(actions.setReadOnlyMode(location.isReadOnly || false));
- if (location.uuid !== currentLocationId) {
- dispatch(LocationIndexActions.clearDirectoryIndex());
- }
- dispatch(actions.setCurrentLocationId(location.uuid));
+ dispatch(actions.changeLocation(location));
dispatch(actions.loadDirectoryContent(location.paths[0]));
return true;
})
@@ -1292,10 +1302,7 @@ export const actions = {
} else {
PlatformIO.disableObjectStoreSupport();
dispatch(actions.setReadOnlyMode(location.isReadOnly || false));
- if (location.uuid !== currentLocationId) {
- dispatch(LocationIndexActions.clearDirectoryIndex());
- }
- dispatch(actions.setCurrentLocationId(location.uuid));
+ dispatch(actions.changeLocation(location));
dispatch(actions.loadDirectoryContent(location.paths[0]));
if (Pro && Pro.Watcher && location.watchForChanges) {
Pro.Watcher.watchFolder(location.paths[0], dispatch, actions);
diff --git a/app/utils/paths.ts b/app/utils/paths.ts
index 84bf1218f..1522934ed 100644
--- a/app/utils/paths.ts
+++ b/app/utils/paths.ts
@@ -17,7 +17,8 @@
*/
import AppConfig from '../config';
-import { Tag } from '../reducers/taglibrary';
+import { Tag } from '-/reducers/taglibrary';
+import { Location } from '-/reducers/locations';
export function baseName(
dirPath: string,
@@ -352,3 +353,16 @@ export function extractTags(
}
return cleanedTags;
}
+
+export function extractLocation(filePath: string, locations: Array<Location>) {
+ const path = filePath.replace(/[/\\]/g, '');
+ for (let i = 0; i < locations.length; i += 1) {
+ const locationPath = locations[i].path
+ ? locations[i].path.replace(/[/\\]/g, '')
+ : locations[i].paths[0].replace(/[/\\]/g, '');
+ if (path.startsWith(locationPath)) {
+ return locations[i];
+ }
+ }
+ return undefined;
+}