TagSpaces is an offline, open source, document manager with tagging support
fix revisions locationId and switch location type (#2007)
Stanimir34ec9ac6e346
diff --git a/app/components/Revisions.tsx b/app/components/Revisions.tsxindex a2ce4d62a..cb21b3f59 100644--- a/app/components/Revisions.tsx+++ b/app/components/Revisions.tsx@@ -46,12 +46,15 @@ import FilePreviewDialog from '-/components/dialogs/FilePreviewDialog';import { useTranslation } from 'react-i18next';import { useOpenedEntryContext } from '-/hooks/useOpenedEntryContext';import { usePlatformFacadeContext } from '-/hooks/usePlatformFacadeContext';+import { useCurrentLocationContext } from '-/hooks/useCurrentLocationContext';const initialRowsPerPage = 10;function Revisions() {const { t } = useTranslation();// const dispatch: AppDispatch = useDispatch();+ const { switchLocationTypeByID, switchCurrentLocationType } =+ useCurrentLocationContext();const { openedEntries, updateOpenedFile } = useOpenedEntryContext();const { copyFilePromiseOverwrite } = usePlatformFacadeContext();const [rows, setRows] = useState<Array<TS.FileSystemEntry>>([]);@@ -85,9 +88,16 @@ function Revisions() {backupFilePath,PlatformIO.getDirSeparator(),);- PlatformIO.listDirectoryPromise(backupPath, []).then((h) =>- setRows(h.sort((a, b) => (a.lmdt < b.lmdt ? 1 : -1))),- );+ switchLocationTypeByID(openedFile.locationId)+ .then(() => {+ PlatformIO.listDirectoryPromise(backupPath, []).then((h) => {+ setRows(h.sort((a, b) => (a.lmdt < b.lmdt ? 1 : -1)));+ return switchCurrentLocationType();+ });+ })+ .catch(() => {+ return switchCurrentLocationType();+ });},);}diff --git a/app/components/dialogs/FilePreviewDialog.tsx b/app/components/dialogs/FilePreviewDialog.tsxindex 3ff668f9c..a64403471 100644--- a/app/components/dialogs/FilePreviewDialog.tsx+++ b/app/components/dialogs/FilePreviewDialog.tsx@@ -24,21 +24,16 @@ import Dialog from '@mui/material/Dialog';import DialogCloseButton from '-/components/dialogs/DialogCloseButton';import { extractContainingDirectoryPath } from '@tagspaces/tagspaces-common/paths';import DraggablePaper from '-/components/DraggablePaper';-import {- actions as AppActions,- AppDispatch,- OpenedEntry,-} from '-/reducers/app';+import { OpenedEntry } from '-/reducers/app';import { TS } from '-/tagspaces.namespace';-import { findExtensionsForEntry } from '-/services/utils-io';import { getCurrentTheme, getSupportedFileTypes } from '-/reducers/settings';-import { useSelector, useDispatch } from 'react-redux';+import { useSelector } from 'react-redux';import FileView from '-/components/FileView';import useEventListener from '-/utils/useEventListener';import PlatformIO from '-/services/platform-facade';import AppConfig from '-/AppConfig';-import { actions as LocationActions } from '-/reducers/locations';import { useCurrentLocationContext } from '-/hooks/useCurrentLocationContext';+import { useOpenedEntryContext } from '-/hooks/useOpenedEntryContext';interface Props {open: boolean;@@ -51,7 +46,8 @@ function FilePreviewDialog(props: Props) {//const dispatch: AppDispatch = useDispatch();const { switchLocationTypeByID, switchCurrentLocationType } =useCurrentLocationContext();- const supportedFileTypes = useSelector(getSupportedFileTypes);+ const { openedEntries } = useOpenedEntryContext();+ // const supportedFileTypes = useSelector(getSupportedFileTypes);const currentTheme = useSelector(getCurrentTheme);const fileViewer: MutableRefObject<HTMLIFrameElement> =useRef<HTMLIFrameElement>(null);@@ -59,14 +55,17 @@ function FilePreviewDialog(props: Props) {useRef<HTMLDivElement>(null);const eventID = useRef<string>(getUuid());- const openedFile: OpenedEntry = fsEntry- ? findExtensionsForEntry(- fsEntry.uuid,- supportedFileTypes,- fsEntry.path,- fsEntry.isFile,- )- : undefined;+ const openedEntry: OpenedEntry = openedEntries[0];+ const openedFile: OpenedEntry =+ fsEntry && openedEntry+ ? {+ ...openedEntry,+ ...(fsEntry.uuid && { uuid: fsEntry.uuid }),+ path: fsEntry.path,+ isFile: fsEntry.isFile,+ editMode: false,+ }+ : undefined;useEventListener('message', (e) => {if (typeof e.data === 'string') {diff --git a/app/electron-tray-menu.ts b/app/electron-tray-menu.tsindex f71c81557..8c5a07643 100644--- a/app/electron-tray-menu.ts+++ b/app/electron-tray-menu.ts@@ -98,7 +98,7 @@ export default function buildTrayIconMenu(mainPageProps: any, i18n, isMacLike) {let icon = nativeImage.createFromDataURL(icon2xWhite);if (!tray) {- if (process.platform === 'darwin') {+ if (process.platform === 'darwin' || process.platform === 'win32') {icon = nativeImage.createFromDataURL(icon1x);icon.addRepresentation({scaleFactor: 2.0,diff --git a/app/reducers/app.ts b/app/reducers/app.tsindex 8b25be9ff..342c703d0 100644--- a/app/reducers/app.ts+++ b/app/reducers/app.ts@@ -120,7 +120,7 @@ export type OpenedEntry = {url?: string;size: number;lmdt: number;- locationId: string;+ locationId?: string;viewingExtensionPath: string;viewingExtensionId: string;editingExtensionPath?: string;diff --git a/app/services/utils-io.ts b/app/services/utils-io.tsindex 9ca87a75c..7957b7ffa 100644--- a/app/services/utils-io.ts+++ b/app/services/utils-io.ts@@ -308,53 +308,66 @@ export function findExtensionPathForId(return 'node_modules/' + extensionId;}-export function findExtensionsForEntry(- uuid: string,- supportedFileTypes: Array<any>,- entryPath: string,- isFile = true,+export function addExtensionsForEntry(+ openedEntry: OpenedEntry,+ supportedFileTypes: Array<TS.FileTypes>,): OpenedEntry {const fileExtension = extractFileExtension(- entryPath,+ openedEntry.path,PlatformIO.getDirSeparator(),).toLowerCase();- const viewingExtensionPath = isFile- ? findExtensionPathForId('@tagspaces/extensions/text-viewer')- : 'about:blank';- const fileForOpening: OpenedEntry = {- uuid: uuid,- path: entryPath,- viewingExtensionPath,- viewingExtensionId: '',- isFile,- // changed: false,- locationId: undefined,- lmdt: 0,- size: 0,- };- supportedFileTypes.map((fileType) => {- if (fileType.viewer && fileType.type.toLowerCase() === fileExtension) {- fileForOpening.viewingExtensionId = fileType.viewer;- if (fileType.color) {- fileForOpening.color = fileType.color;- }- fileForOpening.viewingExtensionPath = findExtensionPathForId(- fileType.viewer,- fileType.extensionExternalPath,++ const fileForOpening = { ...openedEntry };+ const fileType: TS.FileTypes = supportedFileTypes.find(+ (fileType) =>+ fileType.viewer && fileType.type.toLowerCase() === fileExtension,+ );+ if (fileType) {+ fileForOpening.viewingExtensionId = fileType.viewer;+ if (fileType.color) {+ fileForOpening.color = fileType.color;+ }+ fileForOpening.viewingExtensionPath = findExtensionPathForId(+ fileType.viewer,+ //fileType.extensionExternalPath,+ );+ if (fileType.editor && fileType.editor.length > 0) {+ fileForOpening.editingExtensionId = fileType.editor;+ fileForOpening.editingExtensionPath = findExtensionPathForId(+ fileType.editor,+ //fileType.extensionExternalPath,);- if (fileType.editor && fileType.editor.length > 0) {- fileForOpening.editingExtensionId = fileType.editor;- fileForOpening.editingExtensionPath = findExtensionPathForId(- fileType.editor,- fileType.extensionExternalPath,- );- }}- return true;- });+ } else {+ fileForOpening.viewingExtensionPath = openedEntry.isFile+ ? findExtensionPathForId('@tagspaces/extensions/text-viewer')+ : 'about:blank';+ }return fileForOpening;}+export function findExtensionsForEntry(+ uuid: string,+ supportedFileTypes: Array<any>,+ entryPath: string,+ isFile = true,+): OpenedEntry {+ return addExtensionsForEntry(+ {+ ...(uuid && { uuid: uuid }),+ path: entryPath,+ viewingExtensionPath: 'about:blank',+ viewingExtensionId: '',+ isFile,+ // changed: false,+ // locationId: undefined,+ lmdt: 0,+ size: 0,+ },+ supportedFileTypes,+ );+}+export function getNextFile(pivotFilePath?: string,lastSelectedEntry?: string,