Skip to content

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

Adding back button (#1808)

Ilian5275cd76515e
diff --git a/app/components/AppOnboarding.tsx b/app/components/AppOnboarding.tsx
deleted file mode 100644
index e32e439f8..000000000
--- a/app/components/AppOnboarding.tsx
+++ /dev/null
@@ -1,61 +0,0 @@
-/*
-/!**
- * TagSpaces - universal file and folder organizer
- * Copyright (C) 2017-present TagSpaces UG (haftungsbeschraenkt)
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License (version 3) as
- * published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <https://www.gnu.org/licenses/>.
- *
- *!/
-
-import React, { Component } from 'react';
-import Joyride from 'react-joyride';
-import i18n from '../services/i18n';
-
-class AppOnboarding extends Component {
- state = {
- run: false
- };
-
- /!* componentDidMount() {
- setTimeout(() => {
- this.setState({
- run: true
- });
- }, 1000);
- } *!/
-
- callback = data => {
- // const { action, index, type } = data;
- };
-
- render() {
- const { run } = this.state;
- const steps = [
- {
- target: '[data-tid=createNewLocation]',
- content: i18n.t('welcomeContent'),
- placement: 'bottom'
- },
- {
- target: '[data-tid=aboutTagSpaces]',
- content: 'Hello world',
- placement: 'bottom'
- }
- ];
- // @ts-ignore
- return <Joyride steps={steps} run={run} callback={this.callback} />;
- }
-}
-
-export default AppOnboarding;
-*/
diff --git a/app/components/FolderContainer.tsx b/app/components/FolderContainer.tsx
index 83b44c9e1..5e73de9a0 100644
--- a/app/components/FolderContainer.tsx
+++ b/app/components/FolderContainer.tsx
@@ -557,13 +557,21 @@ function FolderContainer(props: Props) {
>
<MainMenuIcon />
</IconButton>
- <IconButton id="goBackButton" onClick={goBack}>
- <GoBackIcon />
- </IconButton>
- {isDesktopMode && (
- <IconButton id="goForwardButton" onClick={goForward}>
- <GoForwardIcon />
+ <Tooltip
+ title={
+ i18n.t('core:goback') + ' - ' + i18n.t('core:gobackClarification')
+ }
+ >
+ <IconButton id="goBackButton" onClick={goBack}>
+ <GoBackIcon />
</IconButton>
+ </Tooltip>
+ {isDesktopMode && (
+ <Tooltip title={i18n.t('core:goforward')}>
+ <IconButton id="goForwardButton" onClick={goForward}>
+ <GoForwardIcon />
+ </IconButton>
+ </Tooltip>
)}
<SearchBox
open={isSearchVisible}
diff --git a/app/components/dialogs/RenameEntryDialog.tsx b/app/components/dialogs/RenameEntryDialog.tsx
index a4c6f5397..af2070224 100644
--- a/app/components/dialogs/RenameEntryDialog.tsx
+++ b/app/components/dialogs/RenameEntryDialog.tsx
@@ -89,14 +89,10 @@ function RenameEntryDialog(props: Props) {
const [ignored, forceUpdate] = useReducer(x => x + 1, 0);
const onInputFocus = event => {
- // https://github.com/mui-org/material-ui/issues/1594
- // const timer = setTimeout(() => {
if (name.current) {
event.preventDefault();
const { target } = event;
target.focus();
- // inputElement.focus();
- // if (defaultName) {
const indexOfBracket = name.current.indexOf(AppConfig.beginTagContainer);
const indexOfDot = name.current.lastIndexOf('.');
let endRange = name.current.length;
@@ -106,11 +102,7 @@ function RenameEntryDialog(props: Props) {
endRange = indexOfDot;
}
target.setSelectionRange(0, endRange);
- // }
}
- // }, 100);
-
- // return () => clearTimeout(timer);
};
const handleInputChange = (event: React.ChangeEvent<HTMLInputElement>) => {
diff --git a/app/components/dialogs/settings/SettingsGeneral.tsx b/app/components/dialogs/settings/SettingsGeneral.tsx
index 8e4cecc50..841e66602 100644
--- a/app/components/dialogs/settings/SettingsGeneral.tsx
+++ b/app/components/dialogs/settings/SettingsGeneral.tsx
@@ -136,13 +136,6 @@ function SettingsGeneral(props: Props) {
onChange={(event: any) => {
props.setLanguage(event.target.value);
PlatformIO.setLanguage(event.target.value);
- // TODO remove (language state is changed in settings reducer and components will be reloaded without this)
- /* const { currentTheme } = props.settings;
- const newTheme = currentTheme === 'dark' ? 'light' : 'dark';
- props.setCurrentTheme(newTheme);
- setTimeout(() => {
- props.setCurrentTheme(currentTheme);
- }, 500); */
}}
input={<Input id="languageSelector" />}
>
diff --git a/app/containers/MainPage.tsx b/app/containers/MainPage.tsx
index b24ef610f..dbc045b58 100644
--- a/app/containers/MainPage.tsx
+++ b/app/containers/MainPage.tsx
@@ -362,14 +362,30 @@ function MainPage(props: Props) {
function goForward() {
window.history.forward();
- props.openLink(window.location.href, { fullWidth: false });
+ window.addEventListener(
+ 'popstate',
+ () => {
+ props.openLink(window.location.href, { fullWidth: false });
+ },
+ { once: true }
+ );
}
function goBack() {
- console.log('current href: ' + decodeURIComponent(window.location.href));
- window.history.back();
- props.openLink(window.location.href, { fullWidth: false });
- console.log('next href: ' + decodeURIComponent(window.location.href));
+ // console.log(
+ // '>>> current href: ' + decodeURIComponent(window.location.href)
+ // );
+ window.history.back(); // window.history.go(-1);
+ window.addEventListener(
+ 'popstate',
+ () => {
+ props.openLink(window.location.href, { fullWidth: false });
+ // console.log(
+ // '>>> last href: ' + decodeURIComponent(window.location.href)
+ // );
+ },
+ { once: true }
+ );
}
useEffect(() => {
diff --git a/app/locales/en/core.json b/app/locales/en/core.json
index a917a8183..f7496b529 100644
--- a/app/locales/en/core.json
+++ b/app/locales/en/core.json
@@ -528,6 +528,7 @@
"filesLimit": "Max. files to be displayed in a folder",
"scrollFilesLimit": "Files to be loaded on scroll down",
"goback": "Go Back",
+ "gobackClarification": "Navigate to last opened file, folder or location",
"goforward": "Go Forward",
"switchSimpleMode": "Simple Mode",
"switchAdvancedMode": "Advanced Mode",
diff --git a/app/main.dev.ts b/app/main.dev.ts
index c35fd4c1d..2ffc96c01 100644
--- a/app/main.dev.ts
+++ b/app/main.dev.ts
@@ -479,10 +479,6 @@ async function createAppWindow() {
}
});
- /* setTimeout(() => {
- mainWindow.toggleDevTools(); // debugging
- }, 2000); */
-
const winUserAgent =
'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.77 Safari/537.36';
const testWinOnUnix = false; // set to true to simulate windows os, useful for testing s3 handling
@@ -499,8 +495,6 @@ async function createAppWindow() {
if (!mainWindow) {
throw new Error('"mainWindow" is not defined');
}
- // mainWindow.show();
- // (global as any).splashWorkerWindow.hide(); // Comment for easy debugging of the worker (global as any).splashWorkerWindow.show();
if (portableMode) {
mainWindow.setTitle(mainWindow.title + ' Portable 🔌');
}
@@ -513,12 +507,6 @@ async function createAppWindow() {
// in an array if your app supports multi windows, this is the time
// when you should delete the corresponding element.
mainWindow = null;
- /* try {
- (global as any).splashWorkerWindow.close();
- (global as any).splashWorkerWindow = null;
- } catch (err) {
- // console.warn('Error closing the splash window. ' + err);
- } */
});
mainWindow.webContents.on('crashed', () => {
diff --git a/app/reducers/app.ts b/app/reducers/app.ts
index bf91277a1..ee627ed8f 100644
--- a/app/reducers/app.ts
+++ b/app/reducers/app.ts
@@ -1194,6 +1194,7 @@ export const actions = {
currentLocation ? currentLocation.ignorePatternPaths : []
)
.then(results => {
+ updateHistory(currentLocation, directoryPath);
if (results !== undefined) {
// console.debug('app listDirectoryPromise resolved:' + results.length);
prepareDirectoryContent(
@@ -2402,6 +2403,7 @@ export const actions = {
} else {
openLocationTimer = 0;
}
+ // setTimeout is needed for case of a location switch, if not location swith the timer is 0
setTimeout(() => {
if (isCloudLocation) {
PlatformIO.enableObjectStoreSupport(targetLocation).then(() => {
@@ -2436,7 +2438,10 @@ export const actions = {
});
} else {
// local files case
- const locationPath = PlatformIO.getLocationPath(targetLocation);
+ // const locationPath = PlatformIO.getLocationPath(targetLocation);
+ const locationPath =
+ targetLocation.path ||
+ (targetLocation.paths && targetLocation.paths[0]);
if (directoryPath && directoryPath.length > 0) {
if (
directoryPath.includes('../') ||
@@ -2453,6 +2458,12 @@ export const actions = {
}
const dirFullPath =
locationPath + PlatformIO.getDirSeparator() + directoryPath;
+ // console.log(
+ // '>>> Openlink Local Directory path: ' +
+ // directoryPath +
+ // ' full: ' +
+ // dirFullPath
+ // );
dispatch(actions.loadDirectoryContent(dirFullPath, false, true));
}
diff --git a/app/reducers/locations.ts b/app/reducers/locations.ts
index 9fdf0fda4..44f1856f2 100644
--- a/app/reducers/locations.ts
+++ b/app/reducers/locations.ts
@@ -285,9 +285,7 @@ export const getLocationByPath = (
): TS.Location | null =>
state.locations.find(location => location.path === path);
export const getDefaultLocationId = (state: any): string | undefined => {
- let foundLocation = state.locations.find(
- location => location.isDefault && !location.isReadOnly
- );
+ let foundLocation = state.locations.find(location => location.isDefault);
return foundLocation ? foundLocation.uuid : undefined;
};
export const getCurrentLocation = (state: any): string | undefined => {
diff --git a/app/services/utils-io.ts b/app/services/utils-io.ts
index f4ef1312d..46248ef02 100644
--- a/app/services/utils-io.ts
+++ b/app/services/utils-io.ts
@@ -1380,6 +1380,6 @@ export function setLocationType(location: TS.Location): Promise<boolean> {
return Promise.resolve(false);
}
-export function getUuid(version = 1): string {
- return version === 1 ? uuidv1() : uuidv4();
+export function getUuid(version = 4): string {
+ return version === 4 ? uuidv4() : uuidv1();
}
diff --git a/app/utils/dom.ts b/app/utils/dom.ts
index 6b8dfe9c5..c318bd629 100644
--- a/app/utils/dom.ts
+++ b/app/utils/dom.ts
@@ -1,4 +1,8 @@
import { locationType } from '@tagspaces/tagspaces-common/misc';
+import {
+ normalizePath,
+ cleanTrailingDirSeparator
+} from '@tagspaces/tagspaces-common/paths';
import { TS } from '-/tagspaces.namespace';
import PlatformIO from '-/services/platform-facade';
@@ -21,7 +25,7 @@ export function getURLParameter(paramName: string, url?: string): string {
}
export function clearAllURLParams() {
- window.history.pushState('', document.title, window.location.pathname);
+ window.history.pushState(null, null, window.location.pathname);
// console.log(window.location.href);
}
@@ -31,19 +35,38 @@ export function clearURLParam(paramName) {
// Delete the foo parameter.
params.delete(paramName);
- window.history.pushState(
- '',
- document.title,
- window.location.pathname + '?' + params
- );
+ window.history.pushState(null, null, window.location.pathname + '?' + params);
// console.log(window.location.href);
}
+function cleanFrontDirSeparator(dirPath) {
+ if (dirPath) {
+ if (dirPath.startsWith('\\')) {
+ return dirPath.substring(2);
+ }
+ if (dirPath.startsWith('/')) {
+ return dirPath.substring(1);
+ }
+ return dirPath;
+ }
+ return '';
+}
+
export function updateHistory(
currentLocation: TS.Location,
currentDirectory: string,
entryPath?: string
) {
+ const currentDirectoryPath = cleanTrailingDirSeparator(currentDirectory);
+ const entryPathNormed = cleanTrailingDirSeparator(entryPath);
+ // console.log(
+ // '>>> Updating history: ' +
+ // currentLocation.name +
+ // ' dir: ' +
+ // currentDirectoryPath +
+ // ' entry: ' +
+ // entryPathNormed
+ // );
if (currentLocation) {
// const isCloudLocation = currentLocation.type === locationType.TYPE_CLOUD;
let urlParams = '?';
@@ -52,21 +75,33 @@ export function updateHistory(
if (currentLocation && currentLocation.uuid) {
urlParams += 'tslid=' + encodeURIComponent(currentLocation.uuid);
- currentLocationPath = PlatformIO.getLocationPath(currentLocation);
+ currentLocationPath =
+ currentLocation.path ||
+ (currentLocation.paths && currentLocation.paths[0]); // PlatformIO.getLocationPath(currentLocation);
+ currentLocationPath = cleanTrailingDirSeparator(currentLocationPath);
+ // console.log('>>> history current location path: ' + currentLocationPath);
}
- if (currentDirectory && currentDirectory.length > 0) {
- const currentDir = isCloudLocation
- ? currentDirectory
- : currentDirectory.replace(currentLocationPath, '');
- urlParams += '&tsdpath=' + encodeURIComponent(currentDir);
+ if (currentDirectoryPath && currentDirectoryPath.length > 0) {
+ let currentRelDir = isCloudLocation
+ ? currentDirectoryPath
+ : currentDirectoryPath.replace(currentLocationPath, '');
+ currentRelDir = cleanFrontDirSeparator(currentRelDir);
+ // console.log('>>> history current rel dir path: ' + currentRelDir);
+ if (currentRelDir) {
+ urlParams += '&tsdpath=' + encodeURIComponent(currentRelDir);
+ }
}
- if (entryPath && entryPath.length > 0) {
- const ePath = isCloudLocation
- ? entryPath
- : entryPath.replace(currentLocationPath, '');
- urlParams += '&tsepath=' + encodeURIComponent(ePath);
+ if (entryPathNormed && entryPathNormed.length > 0) {
+ let eRelPath = isCloudLocation
+ ? entryPathNormed
+ : entryPathNormed.replace(currentLocationPath, '');
+ eRelPath = cleanFrontDirSeparator(eRelPath);
+ // console.log('>>> history current rel entry path: ' + eRelPath);
+ if (eRelPath) {
+ urlParams += '&tsepath=' + encodeURIComponent(eRelPath);
+ }
}
const localePar = getURLParameter('locale');
@@ -74,8 +109,8 @@ export function updateHistory(
urlParams += '&locale=' + localePar;
}
- window.history.pushState('', document.title, urlParams);
- // console.log(window.location.href);
+ window.history.pushState(null, null, urlParams);
+ console.log('href updated: ' + window.location.href);
}
}