Skip to content

Commit

Permalink
fix(PageInfoBar): Update timestamp when page gets saved via "Done" bu…
Browse files Browse the repository at this point in the history
…tton

Requires nextcloud/text#6560

Fixes: #1371

Signed-off-by: Jonas <jonas@freesources.org>
  • Loading branch information
mejo- committed Oct 24, 2024
1 parent 5661614 commit c3367ea
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 14 deletions.
31 changes: 22 additions & 9 deletions src/components/Page/TextEditor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand Down Expand Up @@ -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()
}
},
},

Expand Down Expand Up @@ -141,7 +151,7 @@ export default {
}
},

stopEdit() {
async stopEdit() {
// switch back to edit if there's no content
if (!this.pageContent?.trim()) {
this.setTextEdit()
Expand All @@ -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)
}
}
},

Expand Down
1 change: 1 addition & 0 deletions src/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
5 changes: 1 addition & 4 deletions src/mixins/editorMixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,6 @@ export default {
currentPage: this.pageInfoBarPage || this.pageToUse,
},
},
onLinkClick: (_event, attrs) => {
this.followLink(_event, attrs)
},
onOutlineToggle: (visible) => {
this.toggleOutlineFromEditor(visible)
},
Expand Down Expand Up @@ -180,7 +177,7 @@ export default {
this.editor?.focus()
},

save() {
async save() {
return this.editor.save()
},

Expand Down
5 changes: 4 additions & 1 deletion src/stores/root.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: () => ({
Expand Down Expand Up @@ -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
},
},
Expand Down

0 comments on commit c3367ea

Please sign in to comment.