TagSpaces is an offline, open source, document manager with tagging support
Cannot change md file if change s3 location (#1818)
Stanimir835db580ffcc
diff --git a/app/components/EntryContainer.tsx b/app/components/EntryContainer.tsxindex 3fe531a02..feebba43c 100644--- a/app/components/EntryContainer.tsx+++ b/app/components/EntryContainer.tsx@@ -187,9 +187,9 @@ interface Props {currentDirectoryPath: string | null;isDesktopMode: boolean;tileServer: TS.MapTileServer;- currentLocationId: string;- switchLocationType: (locationId: string) => Promise<boolean>;- switchCurrentLocationType: () => Promise<boolean>;+ // currentLocationId: string;+ switchLocationType: (locationId: string) => Promise<string | null>;+ switchCurrentLocationType: (currentLocationId) => Promise<boolean>;}const historyKeys = Pro && Pro.history ? Pro.history.historyKeys : {};@@ -201,8 +201,6 @@ function EntryContainer(props: Props) {theme,settings,openedFiles,- loadDirectoryContent,- currentLocationId,currentDirectoryPath,isDesktopMode,toggleEntryFullWidth,@@ -443,7 +441,7 @@ function EntryContainer(props: Props) {// if (!this.state.currentEntry.isFile) {// textFilePath += '/index.html';// }- props.switchLocationType(openedFile.locationId).then(() => {+ props.switchLocationType(openedFile.locationId).then((currentLocationId) => {PlatformIO.loadTextFilePromise(textFilePath,data.preview ? data.preview : false@@ -482,11 +480,11 @@ function EntryContainer(props: Props) {!openedFile.editMode);}- return props.switchCurrentLocationType();+ return props.switchCurrentLocationType(currentLocationId);}).catch(err => {console.warn('Error loading text content ' + err);- return props.switchCurrentLocationType();+ return props.switchCurrentLocationType(currentLocationId);});});break;@@ -558,7 +556,7 @@ function EntryContainer(props: Props) {};const saveFile = (textContent: string) => {- props.switchLocationType(openedFile.locationId).then(() => {+ props.switchLocationType(openedFile.locationId).then((currentLocationId) => {PlatformIO.saveTextFilePromise(openedFile.path, textContent, true).then(result => {// isChanged = false;@@ -568,7 +566,7 @@ function EntryContainer(props: Props) {// changed: false,shouldReload: undefined}).then(() => {- props.switchCurrentLocationType();+ props.switchCurrentLocationType(currentLocationId);});fileChanged.current = false;showNotification(@@ -580,7 +578,7 @@ function EntryContainer(props: Props) {historyKeys.fileEditKey,openedFile.path,openedFile.url,- currentLocationId,+ openedFile.locationId,settings[historyKeys.fileEditKey]);}@@ -592,19 +590,19 @@ function EntryContainer(props: Props) {NotificationTypes.error);console.log('Error saving file ' + openedFile.path + ' - ' + error);- props.switchCurrentLocationType();+ props.switchCurrentLocationType(currentLocationId);});});};const editFile = () => {- props.switchLocationType(openedFile.locationId).then(() => {+ props.switchLocationType(openedFile.locationId).then((currentLocationId) => {updateOpenedFile(openedFile.path, {...openedFile,editMode: true,shouldReload: undefined}).then(() => {- props.switchCurrentLocationType();+ props.switchCurrentLocationType(currentLocationId);});});};@@ -1441,7 +1439,7 @@ function mapStateToProps(state) {isDesktopMode: isDesktopMode(state),tileServer: getMapTileServer(state),language: getCurrentLanguage(state),- currentLocationId: getCurrentLocationId(state)+ // currentLocationId: getCurrentLocationId(state)};}diff --git a/app/components/EntryProperties.tsx b/app/components/EntryProperties.tsxindex 66651c7ae..98ebdf296 100644--- a/app/components/EntryProperties.tsx+++ b/app/components/EntryProperties.tsx@@ -165,8 +165,8 @@ interface Props {addTags: (paths: Array<string>, tags: Array<TS.Tag>) => Promise<boolean>;removeTags: (paths: Array<string>, tags: Array<TS.Tag>) => Promise<boolean>;removeAllTags: (paths: Array<string>) => Promise<boolean>;- switchLocationType: (locationId: string) => Promise<boolean>;- switchCurrentLocationType: () => Promise<boolean>;+ switchLocationType: (locationId: string) => Promise<string | null>;+ switchCurrentLocationType: (currentLocationId: string) => Promise<boolean>;isReadOnlyMode: boolean;// currentDirectoryPath: string | null;tagDelimiter: string;@@ -272,25 +272,25 @@ function EntryProperties(props: Props) {);const nextPath = path + PlatformIO.getDirSeparator() + editName;- props.switchLocationType(props.openedEntry.locationId).then(() => {+ props.switchLocationType(props.openedEntry.locationId).then((currentLocationId) => {if (currentEntry.isFile) {renameFile(currentEntry.path, nextPath).then(() => {- props.switchCurrentLocationType();+ props.switchCurrentLocationType(currentLocationId);return true;}).catch(() => {- props.switchCurrentLocationType();+ props.switchCurrentLocationType(currentLocationId);fileNameRef.current.value = entryName;});} else {renameDirectory(currentEntry.path, editName).then(() => {- props.switchCurrentLocationType();+ props.switchCurrentLocationType(currentLocationId);return true;}).catch(() => {- props.switchCurrentLocationType();+ props.switchCurrentLocationType(currentLocationId);fileNameRef.current.value = entryName;});}@@ -330,7 +330,7 @@ function EntryProperties(props: Props) {return;}if (editDescription.current !== undefined) {- props.switchLocationType(props.openedEntry.locationId).then(() => {+ props.switchLocationType(props.openedEntry.locationId).then((currentLocationId) => {Pro.MetaOperations.saveDescription(currentEntry.path,editDescription.current@@ -338,13 +338,13 @@ function EntryProperties(props: Props) {.then(entryMeta => {editDescription.current = undefined;props.updateOpenedFile(currentEntry.path, entryMeta);- props.switchCurrentLocationType();+ props.switchCurrentLocationType(currentLocationId);return true;}).catch(error => {console.warn('Error saving description ' + error);editDescription.current = undefined;- props.switchCurrentLocationType();+ props.switchCurrentLocationType(currentLocationId);props.showNotification(i18n.t('Error saving description'));});});@@ -389,7 +389,7 @@ function EntryProperties(props: Props) {const setThumb = (filePath, thumbFilePath) => {if (filePath !== undefined) {- return props.switchLocationType(props.openedEntry.locationId).then(() => {+ return props.switchLocationType(props.openedEntry.locationId).then((currentLocationId) => {if (PlatformIO.haveObjectStoreSupport() ||PlatformIO.haveWebDavSupport()@@ -408,7 +408,7 @@ function EntryProperties(props: Props) {? '?' + props.lastThumbnailImageChange: '')*/);- return props.switchCurrentLocationType();+ return props.switchCurrentLocationType(currentLocationId);/*}).catch(err => {props.switchCurrentLocationType();@@ -450,19 +450,19 @@ function EntryProperties(props: Props) {// eslint-disable-next-line no-param-reassigncolor = 'transparent';}- props.switchLocationType(props.openedEntry.locationId).then(() => {+ props.switchLocationType(props.openedEntry.locationId).then((currentLocationId) => {Pro.MetaOperations.saveColor(currentEntry.path, color).then(entryMeta => {// if (props.entryPath === props.currentDirectoryPath) {props.updateOpenedFile(currentEntry.path, entryMeta);- props.switchCurrentLocationType();+ props.switchCurrentLocationType(currentLocationId);/* } else {setCurrentEntry({ ...currentEntry, color });} */return true;}).catch(error => {- props.switchCurrentLocationType();+ props.switchCurrentLocationType(currentLocationId);console.warn('Error saving color for folder ' + error);props.showNotification(i18n.t('Error saving color for folder'));});@@ -499,23 +499,23 @@ function EntryProperties(props: Props) {};*/const handleChange = (name: string, value: Array<TS.Tag>, action: string) => {- props.switchLocationType(props.openedEntry.locationId).then(() => {+ props.switchLocationType(props.openedEntry.locationId).then((currentLocationId) => {if (action === 'remove-value') {if (!value) {// no tags left in the select elementprops.removeAllTags([currentEntry.path]).then(() => {props.updateOpenedFile(currentEntry.path, { tags: [] }).then(() => {- props.switchCurrentLocationType();+ props.switchCurrentLocationType(currentLocationId);});});} else {props.removeTags([currentEntry.path], value).then(() => {- props.switchCurrentLocationType();+ props.switchCurrentLocationType(currentLocationId);});}} else if (action === 'clear') {props.removeAllTags([currentEntry.path]).then(() => {- props.switchCurrentLocationType();+ props.switchCurrentLocationType(currentLocationId);});} else {// create-option or select-option@@ -529,7 +529,7 @@ function EntryProperties(props: Props) {return Promise.resolve(false);});Promise.all(promises).then(() => {- props.switchCurrentLocationType();+ props.switchCurrentLocationType(currentLocationId);});}});diff --git a/app/reducers/app.ts b/app/reducers/app.tsindex 640d9e0f3..a6a2a6bab 100644--- a/app/reducers/app.ts+++ b/app/reducers/app.ts@@ -1716,30 +1716,40 @@ export const actions = {dispatch(actions.setCurrentLocationId(location.uuid));}},+ /**+ * @param location+ * return Promise<currentLocationId> if location is changed or null if location and type is changed+ */switchLocationType: (location: TS.Location) => (dispatch: (action) => void,getState: () => any- ): Promise<boolean> => {+ ): Promise<string | null> => {const { currentLocationId } = getState().app;if (location.uuid !== currentLocationId) {const currentLocation: TS.Location = getLocation(getState(),- getState().app.currentLocationId+ currentLocationId);if (location.type !== currentLocation.type) {- return setLocationType(location);+ return setLocationType(location).then(() => null);+ } else {+ // handle the same location type but different location+ // dispatch(actions.setCurrentLocationId(location.uuid));+ return setLocationType(location).then(() => currentLocationId);}}- return Promise.resolve(false);+ return Promise.resolve(null);},- switchCurrentLocationType: () => (+ switchCurrentLocationType: (currentLocationId?: string) => (dispatch: (action) => void,getState: () => any): Promise<boolean> => {+ // dispatch(actions.setCurrentLocationId(location.uuid));const location: TS.Location = getLocation(getState(),- getState().app.currentLocationId+ currentLocationId || getState().app.currentLocationId);+return setLocationType(location);},openLocationById: (locationId: string) => (