diff --git a/src/components/post_status_form/post_status_form.js b/src/components/post_status_form/post_status_form.js
index f629be12..56bb9e24 100644
--- a/src/components/post_status_form/post_status_form.js
+++ b/src/components/post_status_form/post_status_form.js
@@ -294,12 +294,24 @@ const PostStatusForm = {
isEdit () {
return typeof this.statusId !== 'undefined' && this.statusId.trim() !== ''
},
- // debouncedSaveDraft () {
- // return debounce(this.saveDraft, 3000)
- // },
+ debouncedMaybeAutoSaveDraft () {
+ return debounce(this.maybeAutoSaveDraft, 3000)
+ },
pollFormVisible () {
return this.newStatus.hasPoll
},
+ shouldAutoSaveDraft () {
+ return this.$store.getters.mergedConfig.autoSaveDraft
+ },
+ autoSaveState () {
+ if (this.savable) {
+ return this.$t('post_status.auto_save_saving')
+ } else if (this.newStatus.id) {
+ return this.$t('post_status.auto_save_saved')
+ } else {
+ return this.$t('post_status.auto_save_nothing_new')
+ }
+ },
...mapGetters(['mergedConfig']),
...mapState({
mobileLayout: state => state.interface.mobileLayout
@@ -314,13 +326,13 @@ const PostStatusForm = {
}
},
beforeUnmount () {
- // this.saveDraft()
+ this.maybeAutoSaveDraft()
},
methods: {
statusChanged () {
this.autoPreview()
this.updateIdempotencyKey()
- // this.debouncedSaveDraft()
+ this.debouncedMaybeAutoSaveDraft()
this.savable = true
this.saveInhibited = false
},
@@ -688,12 +700,17 @@ const PostStatusForm = {
.then(id => {
if (this.newStatus.id !== id) {
this.newStatus.id = id
- this.savable = false
}
+ this.savable = false
})
}
return Promise.resolve()
},
+ maybeAutoSaveDraft () {
+ if (this.shouldAutoSaveDraft) {
+ this.saveDraft()
+ }
+ },
abandonDraft () {
return this.$store.dispatch('abandonDraft', { id: this.newStatus.id })
},
diff --git a/src/components/post_status_form/post_status_form.vue b/src/components/post_status_form/post_status_form.vue
index a215b9bd..b8523802 100644
--- a/src/components/post_status_form/post_status_form.vue
+++ b/src/components/post_status_form/post_status_form.vue
@@ -267,6 +267,18 @@
+
+ {{ autoSaveState }}
+
+