TagSpaces is an offline, open source, document manager with tagging support
Changing path of a location not reflected automatically on save
sytolkd1dd358db13c
diff --git a/src/renderer/hooks/CurrentLocationContextProvider.tsx b/src/renderer/hooks/CurrentLocationContextProvider.tsxindex 0cfcca78d..c8edd49e0 100644--- a/src/renderer/hooks/CurrentLocationContextProvider.tsx+++ b/src/renderer/hooks/CurrentLocationContextProvider.tsx@@ -499,11 +499,11 @@ export const CurrentLocationContextProvider = ({}function editLocationInt(location: CommonLocation, openAfterEdit = false) {- allLocations.current = allLocations.current.map((l) =>+ /*allLocations.current = allLocations.current.map((l) =>l.uuid === location.uuid ? location : l,- );+ );*/dispatch(LocationActions.changeLocation(location));- forceUpdate();+ //forceUpdate();if (openAfterEdit) {currentLocationId.current = location.uuid;/*diff --git a/src/renderer/hooks/DirectoryContentContextProvider.tsx b/src/renderer/hooks/DirectoryContentContextProvider.tsxindex 19d6adbb4..52fce00bb 100644--- a/src/renderer/hooks/DirectoryContentContextProvider.tsx+++ b/src/renderer/hooks/DirectoryContentContextProvider.tsx@@ -43,7 +43,7 @@ import {import { TS } from '-/tagspaces.namespace';import { CommonLocation } from '-/utils/CommonLocation';import { arrayBufferToDataURL, updateHistory } from '-/utils/dom';-import { useCancelable } from '-/utils/useCancelable';+import { makeCancelable, useCancelable } from '-/utils/useCancelable';import useFirstRender from '-/utils/useFirstRender';import {cleanFrontDirSeparator,@@ -215,7 +215,7 @@ export const DirectoryContentContextProvider = ({const { t } = useTranslation();const {closeAllLocations,- currentLocationId,+ currentLocation,findLocation,skipInitialDirList,getLocationPath,@@ -253,7 +253,6 @@ export const DirectoryContentContextProvider = ({const broadcast = new BroadcastChannel('ts-directory-channel');const defaultColumnsToShow = 3;- const currentLocation = findLocation();useEffect(() => {if (AppConfig.isElectron) {@@ -333,7 +332,7 @@ export const DirectoryContentContextProvider = ({clearDirectoryContent();exitSearchMode();}- }, [currentLocationId]);+ }, [currentLocation]);useEffect(() => {if (!firstRender && metaActions && metaActions.length > 0) {@@ -909,9 +908,9 @@ export const DirectoryContentContextProvider = ({location: CommonLocation,showHiddenEntries = undefined,): Promise<TS.FileSystemEntry[]> {- const uploadCancelled = new Promise((_resolve, reject) => {+ /*const uploadCancelled = new Promise((_resolve, reject) => {signal.addEventListener('abort', () => reject());- });+ });*/showNotification(t('core:loading'), 'info', false);const resultsLimit = {@@ -950,12 +949,26 @@ export const DirectoryContentContextProvider = ({// console.timeEnd('listDirectoryPromise');return loadDirectoryFailure(error);});- return Promise.race([promise, uploadCancelled]).then(() => {+ const cancelableFetch = makeCancelable(promise, signal);++ return cancelableFetch+ .then((response) => {+ return response;+ })+ .catch((err) => {+ if (err.name === 'AbortError') {+ console.log('Upload was canceled');+ } else {+ console.error('Other error:', err);+ }+ return [];+ });+ /* return Promise.race([promise, uploadCancelled]).then(() => {// useCancelable will call abort when unmounted. After listDirectoryPromise succeeded,// we no longer care about that method of cancellation. Catch here to avoid an unhandled promise rejection.uploadCancelled.catch(() => {});return promise;- });+ });*/}function clearDirectoryContent() {diff --git a/src/renderer/utils/useCancelable.ts b/src/renderer/utils/useCancelable.tsindex c715d7723..ccd6a42d9 100644--- a/src/renderer/utils/useCancelable.ts+++ b/src/renderer/utils/useCancelable.ts@@ -40,3 +40,37 @@ export const useCancelable = (): UseCancelableResult => {},};};++/**+ * Wraps any Promise<T> so that it will reject with+ * an AbortError when signal.abort() is called.+ */+export function makeCancelable<T>(+ promise: Promise<T>,+ signal: AbortSignal,+): Promise<T> {+ // 1) If already aborted, fail fast:+ if (signal.aborted) {+ return Promise.reject(new DOMException('Aborted', 'AbortError'));+ }++ return new Promise<T>((resolve, reject) => {+ // 2) Listener that rejects on abort:+ const onAbort = () => {+ reject(new DOMException('Aborted', 'AbortError'));+ };++ signal.addEventListener('abort', onAbort, { once: true });++ // 3) When the real promise settles, clean up the abort listener:+ promise+ .then((value) => {+ signal.removeEventListener('abort', onAbort);+ resolve(value);+ })+ .catch((err) => {+ signal.removeEventListener('abort', onAbort);+ reject(err);+ });+ });+}