diff options
Diffstat (limited to 'app/assets/javascripts/vue_shared/components/markdown/markdown_editor.vue')
-rw-r--r-- | app/assets/javascripts/vue_shared/components/markdown/markdown_editor.vue | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/app/assets/javascripts/vue_shared/components/markdown/markdown_editor.vue b/app/assets/javascripts/vue_shared/components/markdown/markdown_editor.vue index 52d8aab30d5..6ffebc51ef8 100644 --- a/app/assets/javascripts/vue_shared/components/markdown/markdown_editor.vue +++ b/app/assets/javascripts/vue_shared/components/markdown/markdown_editor.vue @@ -3,8 +3,13 @@ import Autosize from 'autosize'; import axios from '~/lib/utils/axios_utils'; import LocalStorageSync from '~/vue_shared/components/local_storage_sync.vue'; import { updateDraft, clearDraft, getDraft } from '~/lib/utils/autosave'; -import { EDITING_MODE_MARKDOWN_FIELD, EDITING_MODE_CONTENT_EDITOR } from '../../constants'; +import { + EDITING_MODE_MARKDOWN_FIELD, + EDITING_MODE_CONTENT_EDITOR, + CLEAR_AUTOSAVE_ENTRY_EVENT, +} from '../../constants'; import MarkdownField from './field.vue'; +import eventHub from './eventhub'; export default { components: { @@ -124,6 +129,11 @@ export default { getValue: () => this.getValue(), setValue: (val) => this.setValue(val), }); + + eventHub.$on(CLEAR_AUTOSAVE_ENTRY_EVENT, this.clearDraft); + }, + beforeDestroy() { + eventHub.$off(CLEAR_AUTOSAVE_ENTRY_EVENT, this.clearDraft); }, methods: { getValue() { @@ -183,6 +193,10 @@ export default { if (this.markdown) updateDraft(this.autosaveKey, this.markdown); else clearDraft(this.autosaveKey); }, + clearDraft(key) { + if (!this.autosaveKey || key !== this.autosaveKey) return; + clearDraft(this.autosaveKey); + }, togglePreview(value) { if (this.editingMode === EDITING_MODE_MARKDOWN_FIELD) { this.$refs.markdownField.previewMarkdown = value; |