From 86f6fbeb46546e81954606c8e9eb6e6ca83bcd78 Mon Sep 17 00:00:00 2001 From: tusooa Date: Thu, 6 Apr 2023 15:08:35 -0400 Subject: [PATCH] Give the option to auto save drafts --- .../post_status_form/post_status_form.js | 29 +++++++++++++++---- .../post_status_form/post_status_form.vue | 16 ++++++++++ .../settings_modal/tabs/general_tab.vue | 7 +++++ src/i18n/en.json | 7 ++++- src/modules/config.js | 3 +- src/modules/instance.js | 1 + 6 files changed, 55 insertions(+), 8 deletions(-) diff --git a/src/components/post_status_form/post_status_form.js b/src/components/post_status_form/post_status_form.js index d8ef252f..2a20fe60 100644 --- a/src/components/post_status_form/post_status_form.js +++ b/src/components/post_status_form/post_status_form.js @@ -324,12 +324,24 @@ const PostStatusForm = { return false }, - // 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 @@ -344,13 +356,13 @@ const PostStatusForm = { } }, beforeUnmount () { - // this.saveDraft() + this.maybeAutoSaveDraft() }, methods: { statusChanged () { this.autoPreview() this.updateIdempotencyKey() - // this.debouncedSaveDraft() + this.debouncedMaybeAutoSaveDraft() this.savable = true this.saveInhibited = false }, @@ -722,12 +734,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 934b803b..f3561856 100644 --- a/src/components/post_status_form/post_status_form.vue +++ b/src/components/post_status_form/post_status_form.vue @@ -297,6 +297,18 @@ + + {{ autoSaveState }} + +