diff options
Diffstat (limited to 'src/components')
| -rw-r--r-- | src/components/poll/poll.js | 35 | ||||
| -rw-r--r-- | src/components/poll/poll.vue | 4 | ||||
| -rw-r--r-- | src/components/status/status.vue | 2 |
3 files changed, 20 insertions, 21 deletions
diff --git a/src/components/poll/poll.js b/src/components/poll/poll.js index ecacbc35..9988070e 100644 --- a/src/components/poll/poll.js +++ b/src/components/poll/poll.js @@ -3,26 +3,33 @@ import { forEach, map } from 'lodash' export default { name: 'Poll', - props: ['poll', 'statusId'], + props: ['pollId'], components: { Timeago }, data () { return { loading: false, - choices: [], - refreshInterval: null + choices: [] } }, - created () { - this.refreshInterval = setTimeout(this.refreshPoll, 30 * 1000) - // Initialize choices to booleans and set its length to match options - this.choices = this.poll.options.map(_ => false) + mounted () { + this.$store.dispatch('trackPoll', this.pollId) }, destroyed () { - clearTimeout(this.refreshInterval) + this.$store.dispatch('untrackPoll', this.pollId) }, computed: { + poll () { + const storePoll = this.$store.state.polls.pollsObject[this.pollId] + return storePoll || {} + }, + options () { + return (this.poll && this.poll.options) || [] + }, + expiresAt () { + return (this.poll && this.poll.expires_at) || 0 + }, expired () { - return Date.now() > Date.parse(this.poll.expires_at) + return Date.now() > Date.parse(this.expiresAt) }, loggedIn () { return this.$store.state.users.currentUser @@ -33,9 +40,6 @@ export default { totalVotesCount () { return this.poll.votes_count }, - expiresAt () { - return Date.parse(this.poll.expires_at).toLocaleString() - }, containerClass () { return { loading: this.loading @@ -55,11 +59,6 @@ export default { } }, methods: { - refreshPoll () { - if (this.expired) return - this.fetchPoll() - this.refreshInterval = setTimeout(this.refreshPoll, 30 * 1000) - }, percentageForOption (count) { return this.totalVotesCount === 0 ? 0 : Math.round(count / this.totalVotesCount * 100) }, @@ -104,4 +103,4 @@ export default { }) } } -}
\ No newline at end of file +} diff --git a/src/components/poll/poll.vue b/src/components/poll/poll.vue index 4c765ae2..bb67101a 100644 --- a/src/components/poll/poll.vue +++ b/src/components/poll/poll.vue @@ -2,7 +2,7 @@ <div class="poll" v-bind:class="containerClass"> <div class="poll-option" - v-for="(option, index) in poll.options" + v-for="(option, index) in options" :key="index" > <div v-if="showResults" :title="resultTitle(option)" class="option-result"> @@ -50,7 +50,7 @@ {{totalVotesCount}} {{ $t("polls.votes") }} ยท </div> <i18n :path="expired ? 'polls.expired' : 'polls.expires_in'"> - <Timeago :time="this.poll.expires_at" :auto-update="60" :now-threshold="0" /> + <Timeago :time="this.expiresAt" :auto-update="60" :now-threshold="0" /> </i18n> </div> </div> diff --git a/src/components/status/status.vue b/src/components/status/status.vue index 58402f7e..821a7a83 100644 --- a/src/components/status/status.vue +++ b/src/components/status/status.vue @@ -124,7 +124,7 @@ </div> <div v-if="status.poll && status.poll.options"> - <poll :poll="status.poll" :status-id="status.id" /> + <poll :poll-id="status.poll.id" /> </div> <div v-if="status.attachments && (!hideSubjectStatus || showingLongSubject)" class="attachments media-body"> |
