Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(PageInfoBar): Update timestamp when page gets saved via "Done" button #1550

Merged
merged 1 commit into from
Oct 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading