Refresh poll
This commit is contained in:
parent
d661be99c2
commit
9571770e32
|
@ -1,9 +1,12 @@
|
||||||
<template>
|
<template>
|
||||||
<poll-results v-if="currentUserHasVoted" :poll="poll" />
|
<poll-results
|
||||||
|
v-if="currentUserHasVoted"
|
||||||
|
:poll="poll"
|
||||||
|
v-on:poll-refreshed="handlePollUpdate" />
|
||||||
<poll-vote
|
<poll-vote
|
||||||
v-else
|
v-else
|
||||||
:poll="poll"
|
:poll="poll"
|
||||||
v-on:user-has-voted="onUserVote" />
|
v-on:user-has-voted="handlePollUpdate" />
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
|
@ -23,7 +26,7 @@ export default {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
onUserVote (poll) {
|
handlePollUpdate (poll) {
|
||||||
this.poll = poll
|
this.poll = poll
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,7 +12,7 @@
|
||||||
</div>
|
</div>
|
||||||
<footer>
|
<footer>
|
||||||
<div class="refresh">
|
<div class="refresh">
|
||||||
<a href="#">Refresh</a> ·
|
<a href="#" @click="fetchPoll(poll.id)">Refresh</a> ·
|
||||||
</div>
|
</div>
|
||||||
<div class="total">
|
<div class="total">
|
||||||
{{totalVotesCount}} {{ $t("polls.votes") }}
|
{{totalVotesCount}} {{ $t("polls.votes") }}
|
||||||
|
@ -31,8 +31,12 @@ export default {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
percentageForOption: function (count) {
|
percentageForOption (count) {
|
||||||
return (this.totalVotesCount === 0 ? 0 : (count / this.totalVotesCount * 100)).toFixed(1)
|
return (this.totalVotesCount === 0 ? 0 : (count / this.totalVotesCount * 100)).toFixed(1)
|
||||||
|
},
|
||||||
|
async fetchPoll (pollID) {
|
||||||
|
const poll = await this.$store.state.api.backendInteractor.fetchPoll(pollID)
|
||||||
|
this.$emit('poll-refreshed', poll)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -110,7 +110,7 @@
|
||||||
<a v-if="showingMore" href="#" class="status-unhider" @click.prevent="toggleShowMore">{{$t("general.show_less")}}</a>
|
<a v-if="showingMore" href="#" class="status-unhider" @click.prevent="toggleShowMore">{{$t("general.show_less")}}</a>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div v-if="status.poll.votes">
|
<div v-if="status.poll && status.poll.votes">
|
||||||
<poll :poll="status.poll" />
|
<poll :poll="status.poll" />
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
|
@ -46,6 +46,7 @@ const MASTODON_UNMUTE_USER_URL = id => `/api/v1/accounts/${id}/unmute`
|
||||||
const MASTODON_POST_STATUS_URL = '/api/v1/statuses'
|
const MASTODON_POST_STATUS_URL = '/api/v1/statuses'
|
||||||
const MASTODON_MEDIA_UPLOAD_URL = '/api/v1/media'
|
const MASTODON_MEDIA_UPLOAD_URL = '/api/v1/media'
|
||||||
const MASTODON_VOTE_URL = '/api/v1/polls/vote'
|
const MASTODON_VOTE_URL = '/api/v1/polls/vote'
|
||||||
|
const MASTODON_POLL_URL = id => `/api/v1/polls/${id}`
|
||||||
|
|
||||||
import { each, map } from 'lodash'
|
import { each, map } from 'lodash'
|
||||||
import { parseStatus, parseUser, parseNotification, parseAttachment } from '../entity_normalizer/entity_normalizer.service.js'
|
import { parseStatus, parseUser, parseNotification, parseAttachment } from '../entity_normalizer/entity_normalizer.service.js'
|
||||||
|
@ -658,6 +659,16 @@ const vote = ({pollID, optionName, credentials}) => {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const fetchPoll = ({pollID, credentials}) => {
|
||||||
|
return promisedRequest(
|
||||||
|
MASTODON_POLL_URL(encodeURIComponent(pollID)),
|
||||||
|
{
|
||||||
|
method: 'GET',
|
||||||
|
headers: authHeaders(credentials)
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
const apiService = {
|
const apiService = {
|
||||||
verifyCredentials,
|
verifyCredentials,
|
||||||
fetchTimeline,
|
fetchTimeline,
|
||||||
|
@ -701,7 +712,8 @@ const apiService = {
|
||||||
denyUser,
|
denyUser,
|
||||||
suggestions,
|
suggestions,
|
||||||
markNotificationsAsSeen,
|
markNotificationsAsSeen,
|
||||||
vote
|
vote,
|
||||||
|
fetchPoll
|
||||||
}
|
}
|
||||||
|
|
||||||
export default apiService
|
export default apiService
|
||||||
|
|
|
@ -59,7 +59,11 @@ const backendInteractorService = (credentials) => {
|
||||||
}
|
}
|
||||||
|
|
||||||
const vote = (pollID, optionName) => {
|
const vote = (pollID, optionName) => {
|
||||||
return apiService.vote({pollID, optionName})
|
return apiService.vote({credentials, pollID, optionName})
|
||||||
|
}
|
||||||
|
|
||||||
|
const fetchPoll = (pollID) => {
|
||||||
|
return apiService.fetchPoll({credentials, pollID})
|
||||||
}
|
}
|
||||||
|
|
||||||
const startFetching = ({timeline, store, userId = false, tag}) => {
|
const startFetching = ({timeline, store, userId = false, tag}) => {
|
||||||
|
@ -121,7 +125,8 @@ const backendInteractorService = (credentials) => {
|
||||||
fetchFollowRequests,
|
fetchFollowRequests,
|
||||||
approveUser,
|
approveUser,
|
||||||
denyUser,
|
denyUser,
|
||||||
vote
|
vote,
|
||||||
|
fetchPoll
|
||||||
}
|
}
|
||||||
|
|
||||||
return backendInteractorServiceInstance
|
return backendInteractorServiceInstance
|
||||||
|
|
Loading…
Reference in New Issue