From d4444cd0b16b04f3b66e327b3d7f78813a08d863 Mon Sep 17 00:00:00 2001 From: tusooa Date: Fri, 10 Mar 2023 11:24:18 -0500 Subject: [PATCH] Save draft immediately before unmount --- .../post_status_form/post_status_form.js | 30 +++++++++++-------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/src/components/post_status_form/post_status_form.js b/src/components/post_status_form/post_status_form.js index 4e3f327e..322ab0e9 100644 --- a/src/components/post_status_form/post_status_form.js +++ b/src/components/post_status_form/post_status_form.js @@ -297,18 +297,8 @@ const PostStatusForm = { isEdit () { return typeof this.statusId !== 'undefined' && this.statusId.trim() !== '' }, - saveDraft () { - return debounce(() => { - if (this.newStatus.status) { - console.debug('Saving status', this.newStatus) - this.$store.dispatch('addOrSaveDraft', { draft: this.newStatus }) - .then(id => { - if (this.newStatus.id !== id) { - this.newStatus.id = id - } - }) - } - }, 3000) + debouncedSaveDraft () { + return debounce(this.saveDraft, 3000) }, ...mapGetters(['mergedConfig']), ...mapState({ @@ -323,11 +313,14 @@ const PostStatusForm = { } } }, + beforeUnmount () { + this.saveDraft() + }, methods: { statusChanged () { this.autoPreview() this.updateIdempotencyKey() - this.saveDraft() + this.debouncedSaveDraft() }, clearStatus () { const newStatus = this.newStatus @@ -679,6 +672,17 @@ const PostStatusForm = { }, propsToNative (props) { return propsToNative(props) + }, + saveDraft () { + if (this.newStatus.status) { + console.debug('Saving status', this.newStatus) + this.$store.dispatch('addOrSaveDraft', { draft: this.newStatus }) + .then(id => { + if (this.newStatus.id !== id) { + this.newStatus.id = id + } + }) + } } } }