fix refreshing
This commit is contained in:
parent
080921e977
commit
70ba232ce3
|
@ -2,6 +2,7 @@
|
||||||
<poll-results
|
<poll-results
|
||||||
v-if="currentUserHasVoted"
|
v-if="currentUserHasVoted"
|
||||||
:poll="poll"
|
:poll="poll"
|
||||||
|
:status-id="statusId"
|
||||||
v-on:poll-refreshed="handlePollUpdate"
|
v-on:poll-refreshed="handlePollUpdate"
|
||||||
/>
|
/>
|
||||||
<poll-vote
|
<poll-vote
|
||||||
|
|
|
@ -12,7 +12,7 @@
|
||||||
</div>
|
</div>
|
||||||
<footer>
|
<footer>
|
||||||
<div class="refresh">
|
<div class="refresh">
|
||||||
<a href="#" @click="fetchPoll(poll.id)">Refresh</a> ·
|
<a href="#" @click.stop.prevent="fetchPoll(poll.id)">Refresh</a> ·
|
||||||
</div>
|
</div>
|
||||||
<div class="total">
|
<div class="total">
|
||||||
{{totalVotesCount}} {{ $t("polls.votes") }}
|
{{totalVotesCount}} {{ $t("polls.votes") }}
|
||||||
|
@ -24,7 +24,7 @@
|
||||||
<script>
|
<script>
|
||||||
export default {
|
export default {
|
||||||
name: 'PollResults',
|
name: 'PollResults',
|
||||||
props: ['poll'],
|
props: ['poll', 'statusId'],
|
||||||
created () {
|
created () {
|
||||||
console.log(this.poll)
|
console.log(this.poll)
|
||||||
},
|
},
|
||||||
|
@ -37,10 +37,8 @@ export default {
|
||||||
percentageForOption (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) {
|
fetchPoll () {
|
||||||
const poll = await this.$store.state.api.backendInteractor.fetchPoll(pollID)
|
this.$store.dispatch('refreshPoll', { id: this.statusId, pollId: this.poll.id })
|
||||||
console.log(poll)
|
|
||||||
this.$emit('poll-refreshed', poll)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,21 +1,24 @@
|
||||||
<template>
|
<template>
|
||||||
<div class="poll-vote" v-bind:class="containerClass">
|
<form class="poll-vote" v-bind:class="containerClass">
|
||||||
<div
|
<div
|
||||||
class="poll-choice"
|
class="poll-choice"
|
||||||
v-for="(pollOption, index) in poll.options"
|
v-for="(pollOption, index) in poll.options"
|
||||||
:key="index">
|
:key="index"
|
||||||
|
>
|
||||||
<input
|
<input
|
||||||
:disabled="loading"
|
|
||||||
type="checkbox"
|
type="checkbox"
|
||||||
:id="optionID(index)"
|
|
||||||
:value="pollOption.title"
|
|
||||||
name="choice"
|
name="choice"
|
||||||
|
:id="index"
|
||||||
|
:disabled="loading"
|
||||||
|
:value="pollOption.title"
|
||||||
v-model="checks[index]"
|
v-model="checks[index]"
|
||||||
>
|
>
|
||||||
<label :for="optionID(index)">{{pollOption.title}}</label>
|
<label :for="index">
|
||||||
</div>
|
{{pollOption.title}}
|
||||||
<button class="btn btn-default poll-vote-button" @click="onVote">{{$t('polls.vote')}}</button>
|
</label>
|
||||||
</div>
|
</div>
|
||||||
|
<button class="btn btn-default poll-vote-button" type="button" @click="vote">{{$t('polls.vote')}}</button>
|
||||||
|
</form>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
|
@ -36,15 +39,11 @@ export default {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
optionID (index) {
|
vote () {
|
||||||
return `pollOption${this.poll.id}#${index}`
|
|
||||||
},
|
|
||||||
onVote () {
|
|
||||||
this.loading = true
|
this.loading = true
|
||||||
|
|
||||||
const choices = this.checks.map((entry, index) => index).filter(value => typeof value === 'number')
|
const choices = this.checks.map((entry, index) => index).filter(value => typeof value === 'number')
|
||||||
this.$store.dispatch('votePoll', { id: this.statusId, pollId: this.poll.id, choices }).then(poll => {
|
this.$store.dispatch('votePoll', { id: this.statusId, pollId: this.poll.id, choices }).then(poll => {
|
||||||
console.log('vote result:', poll)
|
|
||||||
this.loading = false
|
this.loading = false
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
@ -588,6 +588,12 @@ const statuses = {
|
||||||
commit('updateStatusWithPoll', { id, poll })
|
commit('updateStatusWithPoll', { id, poll })
|
||||||
return poll
|
return poll
|
||||||
})
|
})
|
||||||
|
},
|
||||||
|
refreshPoll ({ rootState, commit }, { id, pollId }) {
|
||||||
|
return rootState.api.backendInteractor.fetchPoll(pollId).then(poll => {
|
||||||
|
commit('updateStatusWithPoll', { id, poll })
|
||||||
|
return poll
|
||||||
|
})
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
mutations
|
mutations
|
||||||
|
|
|
@ -737,13 +737,12 @@ const markNotificationsAsSeen = ({ id, credentials }) => {
|
||||||
}).then((data) => data.json())
|
}).then((data) => data.json())
|
||||||
}
|
}
|
||||||
|
|
||||||
const vote = ({ pollID, choices, credentials }) => {
|
const vote = ({ pollId, choices, credentials }) => {
|
||||||
const form = new FormData()
|
const form = new FormData()
|
||||||
form.append('choices', choices)
|
form.append('choices', choices)
|
||||||
const url = MASTODON_VOTE_URL(encodeURIComponent(pollID))
|
|
||||||
|
|
||||||
return promisedRequest({
|
return promisedRequest({
|
||||||
url: MASTODON_VOTE_URL(encodeURIComponent(pollID)),
|
url: MASTODON_VOTE_URL(encodeURIComponent(pollId)),
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
credentials,
|
credentials,
|
||||||
payload: {
|
payload: {
|
||||||
|
@ -752,12 +751,12 @@ const vote = ({ pollID, choices, credentials }) => {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
const fetchPoll = ({ pollID, credentials }) => {
|
const fetchPoll = ({ pollId, credentials }) => {
|
||||||
return promisedRequest(
|
return promisedRequest(
|
||||||
MASTODON_POLL_URL(encodeURIComponent(pollID)),
|
|
||||||
{
|
{
|
||||||
|
url: MASTODON_POLL_URL(encodeURIComponent(pollId)),
|
||||||
method: 'GET',
|
method: 'GET',
|
||||||
headers: authHeaders(credentials)
|
credentials
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
@ -87,12 +87,12 @@ const backendInteractorService = credentials => {
|
||||||
return apiService.deleteUser({ screen_name, credentials })
|
return apiService.deleteUser({ screen_name, credentials })
|
||||||
}
|
}
|
||||||
|
|
||||||
const vote = (pollID, choices) => {
|
const vote = (pollId, choices) => {
|
||||||
return apiService.vote({ credentials, pollID, choices })
|
return apiService.vote({ credentials, pollId, choices })
|
||||||
}
|
}
|
||||||
|
|
||||||
const fetchPoll = (pollID) => {
|
const fetchPoll = (pollId) => {
|
||||||
return apiService.fetchPoll({ credentials, pollID })
|
return apiService.fetchPoll({ credentials, pollId })
|
||||||
}
|
}
|
||||||
|
|
||||||
const updateNotificationSettings = ({ settings }) => {
|
const updateNotificationSettings = ({ settings }) => {
|
||||||
|
|
Loading…
Reference in New Issue