fix: Make sure to always update card description when navigating awayfix

fix #5254
fix #2705

Signed-off-by: Julius Härtl <jus@bitgrid.net>
This commit is contained in:
Julius Härtl
2023-11-12 12:22:42 +01:00
parent 587b44f7b9
commit 29d5913e8b
2 changed files with 21 additions and 5 deletions

View File

@@ -119,8 +119,10 @@ export default {
this.initialize() this.initialize()
}, },
methods: { methods: {
descriptionChanged(newDesc) { async descriptionChanged(newDesc) {
this.$store.dispatch('updateCardDesc', { ...this.card, description: newDesc }) if (newDesc === this.copiedCard.description) {
return
}
this.copiedCard.description = newDesc this.copiedCard.description = newDesc
}, },
async initialize() { async initialize() {

View File

@@ -187,17 +187,26 @@ export default {
mounted() { mounted() {
this.setupEditor() this.setupEditor()
}, },
beforeDestroy() { async beforeDestroy() {
this?.editor?.destroy() await this.destroyEditor()
}, },
methods: { methods: {
async setupEditor() { async setupEditor() {
this?.editor?.destroy() await this.destroyEditor()
this.descriptionLastEdit = 0
this.description = this.card.description
this.editor = await window.OCA.Text.createEditor({ this.editor = await window.OCA.Text.createEditor({
el: this.$refs.editor, el: this.$refs.editor,
content: this.card.description, content: this.card.description,
readOnly: !this.canEdit, readOnly: !this.canEdit,
onLoaded: () => {
this.descriptionLastEdit = 0
},
onUpdate: ({ markdown }) => { onUpdate: ({ markdown }) => {
if (this.description === markdown) {
this.descriptionLastEdit = 0
return
}
this.description = markdown this.description = markdown
this.updateDescription() this.updateDescription()
}, },
@@ -207,6 +216,10 @@ export default {
}) })
}, },
async destroyEditor() {
await this.saveDescription()
this?.editor?.destroy()
},
addKeyListeners() { addKeyListeners() {
this.$refs.markdownEditor.easymde.codemirror.on('keydown', (a, b) => { this.$refs.markdownEditor.easymde.codemirror.on('keydown', (a, b) => {
if (this.keyExitState === 0 && (b.key === 'Meta' || b.key === 'Alt')) { if (this.keyExitState === 0 && (b.key === 'Meta' || b.key === 'Alt')) {
@@ -287,6 +300,7 @@ export default {
return return
} }
this.descriptionSaving = true this.descriptionSaving = true
await this.$store.dispatch('updateCardDesc', { ...this.card, description: this.description })
this.$emit('change', this.description) this.$emit('change', this.description)
this.descriptionLastEdit = 0 this.descriptionLastEdit = 0
this.descriptionSaving = false this.descriptionSaving = false