diff --git a/src/components/draft/draft.js b/src/components/draft/draft.js index 1914024f..8c4b662b 100644 --- a/src/components/draft/draft.js +++ b/src/components/draft/draft.js @@ -1,8 +1,10 @@ import PostStatusForm from 'src/components/post_status_form/post_status_form.vue' +import ConfirmModal from 'src/components/confirm_modal/confirm_modal.vue' const Draft = { components: { - PostStatusForm + PostStatusForm, + ConfirmModal }, props: { draft: { @@ -12,7 +14,8 @@ const Draft = { }, data () { return { - editing: false + editing: false, + showingConfirmDialog: false } }, computed: { @@ -35,6 +38,23 @@ const Draft = { methods: { toggleEditing () { this.editing = !this.editing + }, + abandon () { + this.showingConfirmDialog = true + }, + doAbandon () { + console.debug('abandoning') + this.$store.dispatch('abandonDraft', { id: this.draft.id }) + .then(() => { + this.hideConfirmDialog() + }) + }, + hideConfirmDialog () { + this.showingConfirmDialog = false + }, + handlePosted () { + console.debug('posted') + this.doAbandon() } } } diff --git a/src/components/draft/draft.vue b/src/components/draft/draft.vue index 5114da70..dbea442b 100644 --- a/src/components/draft/draft.vue +++ b/src/components/draft/draft.vue @@ -1,28 +1,48 @@ @@ -31,5 +51,18 @@ diff --git a/src/i18n/en.json b/src/i18n/en.json index 330d1f4b..7ae47b20 100644 --- a/src/i18n/en.json +++ b/src/i18n/en.json @@ -1158,6 +1158,11 @@ }, "drafts": { "drafts": "Drafts", - "continue": "Continue editing" + "continue": "Continue editing", + "abandon": "Abandon draft", + "abandon_confirm_title": "Abandon confirmation", + "abandon_confirm": "Do you really want to abandon this draft?", + "abandon_confirm_accept_button": "Abandon", + "abandon_confirm_cancel_button": "Keep" } } diff --git a/src/modules/drafts.js b/src/modules/drafts.js index 81199c62..808e6837 100644 --- a/src/modules/drafts.js +++ b/src/modules/drafts.js @@ -6,6 +6,9 @@ export const defaultState = { export const mutations = { addOrSaveDraft (state, { draft }) { state.drafts[draft.id] = draft + }, + abandonDraft (state, { id }) { + delete state.drafts[id] } } @@ -14,6 +17,9 @@ export const actions = { const id = draft.id || (new Date().getTime()).toString() store.commit('addOrSaveDraft', { draft: { ...draft, id } }) return id + }, + abandonDraft (store, { id }) { + store.commit('abandonDraft', { id }) } }