Move polls module to store
This commit is contained in:
parent
22ab848f6b
commit
e3ca5b0a32
4 changed files with 64 additions and 81 deletions
|
|
@ -1,6 +1,7 @@
|
|||
import Timeago from 'components/timeago/timeago.vue'
|
||||
import RichContent from 'components/rich_content/rich_content.jsx'
|
||||
import { forEach, map } from 'lodash'
|
||||
import { usePollsStore } from '../../stores/polls'
|
||||
|
||||
export default {
|
||||
name: 'Poll',
|
||||
|
|
@ -17,20 +18,20 @@ export default {
|
|||
}
|
||||
},
|
||||
created () {
|
||||
if (!this.$store.state.polls.pollsObject[this.pollId]) {
|
||||
this.$store.dispatch('mergeOrAddPoll', this.basePoll)
|
||||
if (!usePollsStore().pollsObject[this.pollId]) {
|
||||
usePollsStore().mergeOrAddPoll(this.basePoll)
|
||||
}
|
||||
this.$store.dispatch('trackPoll', this.pollId)
|
||||
usePollsStore().trackPoll(this.pollId)
|
||||
},
|
||||
unmounted () {
|
||||
this.$store.dispatch('untrackPoll', this.pollId)
|
||||
usePollsStore().untrackPoll(this.pollId)
|
||||
},
|
||||
computed: {
|
||||
pollId () {
|
||||
return this.basePoll.id
|
||||
},
|
||||
poll () {
|
||||
const storePoll = this.$store.state.polls.pollsObject[this.pollId]
|
||||
const storePoll = usePollsStore().pollsObject[this.pollId]
|
||||
return storePoll || {}
|
||||
},
|
||||
options () {
|
||||
|
|
@ -76,9 +77,6 @@ export default {
|
|||
resultTitle (option) {
|
||||
return `${option.votes_count}/${this.totalVotesCount} ${this.$t('polls.votes')}`
|
||||
},
|
||||
fetchPoll () {
|
||||
this.$store.dispatch('refreshPoll', { id: this.statusId, pollId: this.poll.id })
|
||||
},
|
||||
activateOption (index) {
|
||||
// forgive me father: doing checking the radio/checkboxes
|
||||
// in code because of customized input elements need either
|
||||
|
|
@ -106,8 +104,7 @@ export default {
|
|||
vote () {
|
||||
if (this.choiceIndices.length === 0) return
|
||||
this.loading = true
|
||||
this.$store.dispatch(
|
||||
'votePoll',
|
||||
usePollsStore().votePoll(
|
||||
{ id: this.statusId, pollId: this.poll.id, choices: this.choiceIndices }
|
||||
).then(poll => {
|
||||
this.loading = false
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue