From f1a9a0445148bb3f58beb4a0fc258c26335df68a Mon Sep 17 00:00:00 2001 From: Maxim Filippov Date: Wed, 10 Apr 2019 02:07:13 +0200 Subject: [PATCH] Close poll form after status submit --- src/components/poll/poll_form/poll_form.vue | 7 +++--- .../post_status_form/post_status_form.js | 2 ++ .../post_status_form/post_status_form.vue | 2 +- src/modules/poll.js | 23 ++++++++++++++++--- 4 files changed, 26 insertions(+), 8 deletions(-) diff --git a/src/components/poll/poll_form/poll_form.vue b/src/components/poll/poll_form/poll_form.vue index e6cc6a52..7cb5c949 100644 --- a/src/components/poll/poll_form/poll_form.vue +++ b/src/components/poll/poll_form/poll_form.vue @@ -42,17 +42,16 @@ export default { methods: { onAddOption () { if (this.optionsLength < maxOptions) { - this.$store.commit('addPollOption', '') + this.$store.dispatch('addPollOption', { option: '' }) } }, onDeleteOption (index) { - console.log(index) if (this.optionsLength > 1) { - this.$store.commit('deletePollOption', index) + this.$store.dispatch('deletePollOption', { index }) } }, onUpdateOption (e, index) { - this.$store.commit('updatePollOption', { index, option: e.target.value }) + this.$store.dispatch('updatePollOption', { index, option: e.target.value }) } } } diff --git a/src/components/post_status_form/post_status_form.js b/src/components/post_status_form/post_status_form.js index 847cdf1d..9c2ad723 100644 --- a/src/components/post_status_form/post_status_form.js +++ b/src/components/post_status_form/post_status_form.js @@ -275,6 +275,8 @@ const PostStatusForm = { visibility: newStatus.visibility, contentType: newStatus.contentType } + this.$store.dispatch('swapPollOptions', { options: ['', ''] }) + this.pollFormVisible = false this.$refs.mediaUpload.clearFile() this.$emit('posted') let el = this.$el.querySelector('textarea') diff --git a/src/components/post_status_form/post_status_form.vue b/src/components/post_status_form/post_status_form.vue index 773ccc58..2c68c28b 100644 --- a/src/components/post_status_form/post_status_form.vue +++ b/src/components/post_status_form/post_status_form.vue @@ -74,7 +74,7 @@ - +
diff --git a/src/modules/poll.js b/src/modules/poll.js index 39d28556..e0082991 100644 --- a/src/modules/poll.js +++ b/src/modules/poll.js @@ -3,14 +3,31 @@ const poll = { pollOptions: ['', ''] }, mutations: { - addPollOption (state, option) { + ADD_OPTION (state, { option }) { state.pollOptions.push(option) }, - updatePollOption (state, { index, option }) { + UPDATE_OPTION (state, { index, option }) { state.pollOptions[index] = option }, - deletePollOption (state, index) { + DELETE_OPTION (state, { index }) { state.pollOptions.splice(index, 1) + }, + SWAP_OPTIONS (state, { options }) { + state.pollOptions = options + } + }, + actions: { + addPollOption (store, { option }) { + store.commit('ADD_OPTION', { option }) + }, + updatePollOption (store, { index, option }) { + store.commit('UPDATE_OPTION', { index, option }) + }, + deletePollOption (store, { index }) { + store.commit('DELETE_OPTION', { index }) + }, + swapPollOptions (store, { options }) { + store.commit('SWAP_OPTIONS', { options }) } } }