Fix autosave on blur/card change and trigger easymde rerendering

Signed-off-by: Julius Härtl <jus@bitgrid.net>
This commit is contained in:
Julius Härtl
2020-06-12 22:06:48 +02:00
parent 6523328c96
commit 4cc630e808

View File

@@ -152,10 +152,12 @@
@click="clickedPreview" @click="clickedPreview"
v-html="renderedDescription" /> v-html="renderedDescription" />
<VueEasymde v-else <VueEasymde v-else
:key="copiedCard.id"
ref="markdownEditor" ref="markdownEditor"
:value="copiedCard.description" v-model="copiedCard.description"
:configs="mdeConfig" :configs="mdeConfig"
@input="updateDescription" /> @input="updateDescription"
@blur="saveDescription" />
</AppSidebarTab> </AppSidebarTab>
<AppSidebarTab id="attachments" <AppSidebarTab id="attachments"
@@ -356,11 +358,15 @@ export default {
this.initialize() this.initialize()
}, },
methods: { methods: {
initialize() { async initialize() {
if (!this.currentCard) { if (!this.currentCard) {
return return
} }
if (this.copiedCard) {
await this.saveDescription()
}
this.copiedCard = JSON.parse(JSON.stringify(this.currentCard)) this.copiedCard = JSON.parse(JSON.stringify(this.currentCard))
this.allLabels = this.currentCard.labels this.allLabels = this.currentCard.labels
@@ -431,11 +437,7 @@ export default {
this.copiedCard.duedate = null this.copiedCard.duedate = null
this.$store.dispatch('updateCardDue', this.copiedCard) this.$store.dispatch('updateCardDue', this.copiedCard)
}, },
updateDescription(text) { async saveDescription() {
this.copiedCard.description = text
this.copiedCard.descriptionLastEdit = Date.now()
clearTimeout(this.descriptionSaveTimeout)
this.descriptionSaveTimeout = setTimeout(async() => {
if (!Object.prototype.hasOwnProperty.call(this.copiedCard, 'descriptionLastEdit') || this.descriptionSaving) { if (!Object.prototype.hasOwnProperty.call(this.copiedCard, 'descriptionLastEdit') || this.descriptionSaving) {
return return
} }
@@ -443,8 +445,13 @@ export default {
await this.$store.dispatch('updateCardDesc', this.copiedCard) await this.$store.dispatch('updateCardDesc', this.copiedCard)
delete this.copiedCard.descriptionLastEdit delete this.copiedCard.descriptionLastEdit
this.descriptionSaving = false this.descriptionSaving = false
},
updateDescription(text) {
this.copiedCard.descriptionLastEdit = Date.now()
clearTimeout(this.descriptionSaveTimeout)
this.descriptionSaveTimeout = setTimeout(async() => {
await this.saveDescription()
}, 2500) }, 2500)
}, },
closeSidebar() { closeSidebar() {