diff --git a/src/components/Page/TextEditor.vue b/src/components/Page/TextEditor.vue index c33a7c099..f4a8f5746 100644 --- a/src/components/Page/TextEditor.vue +++ b/src/components/Page/TextEditor.vue @@ -31,6 +31,7 @@ import { useCollectivesStore } from '../../stores/collectives.js' import { usePagesStore } from '../../stores/pages.js' import { useVersionsStore } from '../../stores/versions.js' import editorMixin from '../../mixins/editorMixin.js' +import { editorApiUpdateReadonlyBarProps } from '../../constants.js' import pageContentMixin from '../../mixins/pageContentMixin.js' import SkeletonLoading from '../SkeletonLoading.vue' @@ -72,8 +73,17 @@ export default { }, watch: { - 'currentPage.timestamp'() { - this.getPageContent() + 'currentPage.timestamp'(value) { + if (value) { + // Update currentPage in PageInfoBar component through Text editorAPI + if (this.editorApiFlags.includes(editorApiUpdateReadonlyBarProps)) { + this.reader?.updateReadonlyBarProps({ + currentPage: this.pageInfoBarPage || this.pageToUse, + }) + } + + this.getPageContent() + } }, }, @@ -141,7 +151,7 @@ export default { } }, - stopEdit() { + async stopEdit() { // switch back to edit if there's no content if (!this.pageContent?.trim()) { this.setTextEdit() @@ -153,18 +163,21 @@ export default { const changed = this.editorContent && (this.editorContent !== this.davContent) if (changed) { - this.touchPage() - if (!this.isPublic && this.hasVersionsLoaded) { - this.getVersions(this.currentPage.id) - } - // Save pending changes in editor // TODO: detect missing connection and display warning - this.save() + await this.save() .catch(() => { showError(t('collectives', 'Error saving the document. Please try again.')) this.setTextEdit() }) + + // Touch page to update last changed timestamp + this.touchPage() + + // Update loaded versions + if (!this.isPublic && this.hasVersionsLoaded) { + this.getVersions(this.currentPage.id) + } } }, diff --git a/src/constants.js b/src/constants.js index 040b12e25..10c728154 100644 --- a/src/constants.js +++ b/src/constants.js @@ -44,5 +44,6 @@ export const pageModes = { } export const editorApiReaderFileId = 'READER_FILE_ID' +export const editorApiUpdateReadonlyBarProps = 'UPDATE_READONLY_BAR_PROPS' export const sessionUpdateInterval = 90 // in seconds diff --git a/src/mixins/editorMixin.js b/src/mixins/editorMixin.js index d6d556ef4..bbdf45772 100644 --- a/src/mixins/editorMixin.js +++ b/src/mixins/editorMixin.js @@ -118,9 +118,6 @@ export default { currentPage: this.pageInfoBarPage || this.pageToUse, }, }, - onLinkClick: (_event, attrs) => { - this.followLink(_event, attrs) - }, onOutlineToggle: (visible) => { this.toggleOutlineFromEditor(visible) }, @@ -180,7 +177,7 @@ export default { this.editor?.focus() }, - save() { + async save() { return this.editor.save() }, diff --git a/src/stores/root.js b/src/stores/root.js index 8d879fbbe..4b8494ef4 100644 --- a/src/stores/root.js +++ b/src/stores/root.js @@ -5,7 +5,7 @@ import { defineStore } from 'pinia' import { set } from 'vue' -import { editorApiReaderFileId, pageModes } from '../constants.js' +import { editorApiReaderFileId, editorApiUpdateReadonlyBarProps, pageModes } from '../constants.js' export const useRootStore = defineStore('root', { state: () => ({ @@ -39,6 +39,9 @@ export const useRootStore = defineStore('root', { if (this.editorApiVersionCheck('1.1')) { flags.push(editorApiReaderFileId) } + if (this.editorApiVersionCheck('1.2')) { + flags.push(editorApiUpdateReadonlyBarProps) + } return flags }, },