Save draft immediately before unmount

This commit is contained in:
tusooa 2023-03-10 11:24:18 -05:00
parent 4daa272fdf
commit d4444cd0b1
No known key found for this signature in database
GPG Key ID: 42AEC43D48433C51
1 changed files with 17 additions and 13 deletions

View File

@ -297,18 +297,8 @@ const PostStatusForm = {
isEdit () { isEdit () {
return typeof this.statusId !== 'undefined' && this.statusId.trim() !== '' return typeof this.statusId !== 'undefined' && this.statusId.trim() !== ''
}, },
saveDraft () { debouncedSaveDraft () {
return debounce(() => { return debounce(this.saveDraft, 3000)
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)
}, },
...mapGetters(['mergedConfig']), ...mapGetters(['mergedConfig']),
...mapState({ ...mapState({
@ -323,11 +313,14 @@ const PostStatusForm = {
} }
} }
}, },
beforeUnmount () {
this.saveDraft()
},
methods: { methods: {
statusChanged () { statusChanged () {
this.autoPreview() this.autoPreview()
this.updateIdempotencyKey() this.updateIdempotencyKey()
this.saveDraft() this.debouncedSaveDraft()
}, },
clearStatus () { clearStatus () {
const newStatus = this.newStatus const newStatus = this.newStatus
@ -679,6 +672,17 @@ const PostStatusForm = {
}, },
propsToNative (props) { propsToNative (props) {
return 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
}
})
}
} }
} }
} }