Skip to content

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

chore: adjusting icons, improving use of generateSharingLink, cleaning relative paths

Ilian Sapundshiev33f319907479
diff --git a/app/components/CommonIcons.tsx b/app/components/CommonIcons.tsx
index 38f73ffa8..1a38efe37 100644
--- a/app/components/CommonIcons.tsx
+++ b/app/components/CommonIcons.tsx
@@ -40,6 +40,8 @@ export const ParentFolderIcon = props => (
// <ParentFolder {...props} />
);
+export const NavigateToFolderIcon = props => <KeyboardReturnIcon />;
+
export const FolderIcon = props => <Folder {...props} />;
export const MainMenuIcon = props => <Menu {...props} />;
diff --git a/app/components/EntryContainer.tsx b/app/components/EntryContainer.tsx
index ec78e6d2b..37f2c23be 100644
--- a/app/components/EntryContainer.tsx
+++ b/app/components/EntryContainer.tsx
@@ -49,7 +49,10 @@ import ShareIcon from '@mui/icons-material/Share';
import withStyles from '@mui/styles/withStyles';
import RefreshIcon from '@mui/icons-material/Refresh';
import Box from '@mui/material/Box';
-import { ParentFolderIcon } from '-/components/CommonIcons';
+import {
+ ParentFolderIcon,
+ NavigateToFolderIcon
+} from '-/components/CommonIcons';
import { Split } from 'ts-react-splitter';
import { buffer } from '@tagspaces/tagspaces-common/misc';
import AppConfig from '-/AppConfig';
@@ -987,7 +990,7 @@ function EntryContainer(props: Props) {
onClick={navigateToFolder}
size="large"
>
- <ParentFolderIcon />
+ <NavigateToFolderIcon />
</IconButton>
</Tooltip>
{!AppConfig.isCordova && (
diff --git a/app/components/menus/DirectoryMenu.tsx b/app/components/menus/DirectoryMenu.tsx
index 47fa8363c..8ffd53f39 100644
--- a/app/components/menus/DirectoryMenu.tsx
+++ b/app/components/menus/DirectoryMenu.tsx
@@ -31,7 +31,6 @@ import {
generateSharingLink
} from '@tagspaces/tagspaces-common/paths';
import { Pro } from '../../pro';
-import CreateDirectoryDialog from '../dialogs/CreateDirectoryDialog';
import i18n from '-/services/i18n';
import PlatformIO from '-/services/platform-facade';
import {
@@ -48,7 +47,7 @@ import FileUploadContainer, {
FileUploadContainerRef
} from '-/components/FileUploadContainer';
import { TS } from '-/tagspaces.namespace';
-import Links from '-/content/links';
+import { getRelativeEntryPath } from '-/services/utils-io';
import { PerspectiveIDs } from '-/perspectives';
import PlatformFacade from '-/services/platform-facade';
import { getDirectoryMenuItems } from '-/perspectives/common/DirectoryMenuItems';
@@ -124,17 +123,9 @@ function DirectoryMenu(props: Props) {
const locationID = entryFromIndex
? selectedEntries[0]['locationID']
: currentLocation.uuid;
- let relativePath = selectedEntries[0].path;
+ const entryPath = selectedEntries[0].path;
const tmpLoc = locations.find(location => location.uuid === locationID);
- const locationPath = tmpLoc.path;
- if (
- locationPath &&
- relativePath &&
- relativePath.startsWith(locationPath)
- ) {
- // remove location path from entry path if possible
- relativePath = relativePath.substr(locationPath.length);
- }
+ const relativePath = getRelativeEntryPath(tmpLoc, entryPath);
const sharingLink = generateSharingLink(
locationID,
undefined,
diff --git a/app/components/menus/FileMenu.tsx b/app/components/menus/FileMenu.tsx
index 2c9c6e547..08f18b360 100644
--- a/app/components/menus/FileMenu.tsx
+++ b/app/components/menus/FileMenu.tsx
@@ -24,7 +24,7 @@ import MenuItem from '@mui/material/MenuItem';
import Divider from '@mui/material/Divider';
import OpenFile from '@mui/icons-material/SubdirectoryArrowRight';
import OpenFileNatively from '@mui/icons-material/Launch';
-import OpenParentFolder from '@mui/icons-material/FolderOpen';
+import { ParentFolderIcon } from '-/components/CommonIcons';
import OpenFolderInternally from '@mui/icons-material/Folder';
import AddRemoveTags from '@mui/icons-material/Loyalty';
import MoveCopy from '@mui/icons-material/FileCopy';
@@ -50,7 +50,8 @@ import {
generateFileName,
getAllPropertiesPromise,
setFolderBackgroundPromise,
- setFolderThumbnailPromise
+ setFolderThumbnailPromise,
+ getRelativeEntryPath
} from '-/services/utils-io';
import { Pro } from '-/pro';
import { TS } from '-/tagspaces.namespace';
@@ -111,17 +112,9 @@ function FileMenu(props: Props) {
const locationID = entryFromIndex
? selectedEntries[0].locationID
: currentLocation.uuid;
- let relativePath = selectedEntries[0].path;
+ const entryPath = selectedEntries[0].path;
const tmpLoc = locations.find(location => location.uuid === locationID);
- const locationPath = tmpLoc.path;
- if (
- locationPath &&
- relativePath &&
- relativePath.startsWith(locationPath)
- ) {
- // remove location path from entry path if possible
- relativePath = relativePath.substr(locationPath.length);
- }
+ const relativePath = getRelativeEntryPath(tmpLoc, entryPath);
const sharingLink = generateSharingLink(locationID, relativePath);
navigator.clipboard
.writeText(sharingLink)
@@ -306,7 +299,7 @@ function FileMenu(props: Props) {
onClick={openParentFolderInternally}
>
<ListItemIcon>
- <OpenParentFolder />
+ <ParentFolderIcon />
</ListItemIcon>
<ListItemText primary={i18n.t('core:openParentFolder')} />
</MenuItem>
diff --git a/app/reducers/app.ts b/app/reducers/app.ts
index 73181005e..55f94158d 100644
--- a/app/reducers/app.ts
+++ b/app/reducers/app.ts
@@ -53,7 +53,9 @@ import {
loadJSONFile,
merge,
setLocationType,
- getUuid
+ getUuid,
+ getRelativeEntryPath,
+ getCleanLocationPath
} from '-/services/utils-io';
import i18n from '../services/i18n';
import { Pro } from '../pro';
@@ -1744,7 +1746,7 @@ export const actions = {
return true;
});
},
- openLocation: (location: TS.Location) => (
+ openLocation: (location: TS.Location, skipInitialDirList?: boolean) => (
dispatch: (action) => void,
getState: () => any
) => {
@@ -1752,16 +1754,6 @@ export const actions = {
Pro.Watcher.stopWatching();
}
if (location.type === locationType.TYPE_CLOUD) {
- // if (!Pro) {
- // dispatch(
- // actions.showNotification(
- // i18n.t('core:thisFunctionalityIsAvailableInPro'),
- // 'warning',
- // true
- // )
- // );
- // return;
- // }
PlatformIO.enableObjectStoreSupport(location)
.then(() => {
dispatch(
@@ -1773,13 +1765,15 @@ export const actions = {
);
dispatch(actions.setReadOnlyMode(location.isReadOnly || false));
dispatch(actions.changeLocation(location));
- dispatch(
- actions.loadDirectoryContent(
- PlatformIO.getLocationPath(location),
- false,
- true
- )
- );
+ if (!skipInitialDirList) {
+ dispatch(
+ actions.loadDirectoryContent(
+ PlatformIO.getLocationPath(location),
+ false,
+ true
+ )
+ );
+ }
return true;
})
.catch(e => {
@@ -1802,13 +1796,15 @@ export const actions = {
}
dispatch(actions.setReadOnlyMode(location.isReadOnly || false));
dispatch(actions.changeLocation(location));
- dispatch(
- actions.loadDirectoryContent(
- PlatformIO.getLocationPath(location),
- true,
- true
- )
- );
+ if (!skipInitialDirList) {
+ dispatch(
+ actions.loadDirectoryContent(
+ PlatformIO.getLocationPath(location),
+ true,
+ true
+ )
+ );
+ }
if (Pro && Pro.Watcher && location.watchForChanges) {
const perspective = getCurrentDirectoryPerspective(getState());
const depth = perspective === PerspectiveIDs.KANBAN ? 3 : 1;
@@ -2072,13 +2068,12 @@ export const actions = {
*/
if (Pro) {
const historyKeys = Pro.history.historyKeys;
+ const relEntryPath = getRelativeEntryPath(currentLocation, fsEntry.path);
if (fsEntry.isFile) {
Pro.history.saveHistory(
historyKeys.fileOpenKey,
fsEntry.path,
- entryForOpening.url
- ? generateSharingLink(currentLocation.uuid, fsEntry.path)
- : undefined,
+ generateSharingLink(currentLocation.uuid, relEntryPath),
currentLocation.uuid,
getState().settings[historyKeys.fileOpenKey]
);
@@ -2086,9 +2081,7 @@ export const actions = {
Pro.history.saveHistory(
historyKeys.folderOpenKey,
fsEntry.path,
- entryForOpening.url
- ? generateSharingLink(currentLocation.uuid, undefined, fsEntry.path)
- : undefined,
+ generateSharingLink(currentLocation.uuid, relEntryPath, relEntryPath),
currentLocation.uuid,
getState().settings[historyKeys.folderOpenKey]
);
@@ -2415,17 +2408,23 @@ export const actions = {
let openLocationTimer = 1000;
const isCloudLocation = targetLocation.type === locationType.TYPE_CLOUD;
const { currentLocationId } = getState().app;
+ let skipListingLocation = directoryPath && directoryPath.length > 0;
if (targetLocation.uuid !== currentLocationId) {
- dispatch(actions.openLocation(targetLocation));
+ dispatch(actions.openLocation(targetLocation, skipListingLocation));
} else {
openLocationTimer = 0;
}
+ const locationPath = getCleanLocationPath(targetLocation);
+
// setTimeout is needed for case of a location switch, if not location swith the timer is 0
setTimeout(() => {
if (isCloudLocation) {
PlatformIO.enableObjectStoreSupport(targetLocation).then(() => {
if (directoryPath && directoryPath.length > 0) {
- const dirFullPath = directoryPath;
+ const dirFullPath =
+ locationPath.length > 0
+ ? locationPath + '/' + directoryPath
+ : directoryPath;
dispatch(
actions.loadDirectoryContent(dirFullPath, false, true)
);
@@ -2455,10 +2454,6 @@ export const actions = {
});
} else {
// local files case
- // const locationPath = PlatformIO.getLocationPath(targetLocation);
- const locationPath =
- targetLocation.path ||
- (targetLocation.paths && targetLocation.paths[0]);
if (directoryPath && directoryPath.length > 0) {
if (
directoryPath.includes('../') ||
@@ -2475,12 +2470,6 @@ 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/services/utils-io.ts b/app/services/utils-io.ts
index 6a54fb3ae..0d8e01e1c 100644
--- a/app/services/utils-io.ts
+++ b/app/services/utils-io.ts
@@ -1384,3 +1384,36 @@ export function setLocationType(location: TS.Location): Promise<boolean> {
export function getUuid(version = 4): string {
return version === 4 ? uuidv4() : uuidv1();
}
+
+export function getCleanLocationPath(location: TS.Location): string {
+ let locationPath = PlatformIO.getLocationPath(location);
+ locationPath = cleanTrailingDirSeparator(locationPath);
+ return locationPath;
+}
+
+export function getRelativeEntryPath(
+ location: TS.Location,
+ entryPath: string
+): string {
+ const entryPathCleaned = cleanTrailingDirSeparator(entryPath);
+ const isCloudLocation = location.type === locationType.TYPE_CLOUD;
+ const currentLocationPath = getCleanLocationPath(location);
+ let relEntryPath = isCloudLocation
+ ? entryPathCleaned
+ : entryPathCleaned.replace(currentLocationPath, '');
+ relEntryPath = cleanFrontDirSeparator(relEntryPath);
+ return relEntryPath;
+}
+
+export function cleanFrontDirSeparator(dirPath) {
+ if (dirPath) {
+ if (dirPath.startsWith('\\')) {
+ return dirPath.substring(2);
+ }
+ if (dirPath.startsWith('/')) {
+ return dirPath.substring(1);
+ }
+ return dirPath;
+ }
+ return '';
+}
diff --git a/app/utils/dom.ts b/app/utils/dom.ts
index c318bd629..7bf68a940 100644
--- a/app/utils/dom.ts
+++ b/app/utils/dom.ts
@@ -1,10 +1,5 @@
-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';
+import { getRelativeEntryPath } from '-/services/utils-io';
export function isVisibleOnScreen(element: any) {
const rectangle = element.getBoundingClientRect();
@@ -39,26 +34,11 @@ export function clearURLParam(paramName) {
// 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 +
@@ -70,34 +50,23 @@ export function updateHistory(
if (currentLocation) {
// const isCloudLocation = currentLocation.type === locationType.TYPE_CLOUD;
let urlParams = '?';
- let currentLocationPath = '';
- const isCloudLocation = currentLocation.type === locationType.TYPE_CLOUD;
-
if (currentLocation && currentLocation.uuid) {
urlParams += 'tslid=' + encodeURIComponent(currentLocation.uuid);
- currentLocationPath =
- currentLocation.path ||
- (currentLocation.paths && currentLocation.paths[0]); // PlatformIO.getLocationPath(currentLocation);
- currentLocationPath = cleanTrailingDirSeparator(currentLocationPath);
- // console.log('>>> history current location path: ' + currentLocationPath);
}
- if (currentDirectoryPath && currentDirectoryPath.length > 0) {
- let currentRelDir = isCloudLocation
- ? currentDirectoryPath
- : currentDirectoryPath.replace(currentLocationPath, '');
- currentRelDir = cleanFrontDirSeparator(currentRelDir);
+ if (currentDirectory && currentDirectory.length > 0) {
+ const currentRelDir = getRelativeEntryPath(
+ currentLocation,
+ currentDirectory
+ );
// console.log('>>> history current rel dir path: ' + currentRelDir);
if (currentRelDir) {
urlParams += '&tsdpath=' + encodeURIComponent(currentRelDir);
}
}
- if (entryPathNormed && entryPathNormed.length > 0) {
- let eRelPath = isCloudLocation
- ? entryPathNormed
- : entryPathNormed.replace(currentLocationPath, '');
- eRelPath = cleanFrontDirSeparator(eRelPath);
+ if (entryPath && entryPath.length > 0) {
+ const eRelPath = getRelativeEntryPath(currentLocation, entryPath);
// console.log('>>> history current rel entry path: ' + eRelPath);
if (eRelPath) {
urlParams += '&tsepath=' + encodeURIComponent(eRelPath);