Voting
This commit is contained in:
parent
69d1fdb8dc
commit
d661be99c2
5 changed files with 42 additions and 8 deletions
|
@ -1,6 +1,9 @@
|
|||
<template>
|
||||
<poll-results v-if="currentUserHasVoted" :poll="poll" />
|
||||
<poll-vote v-else :poll="poll" />
|
||||
<poll-vote
|
||||
v-else
|
||||
:poll="poll"
|
||||
v-on:user-has-voted="onUserVote" />
|
||||
</template>
|
||||
|
||||
<script>
|
||||
|
@ -16,7 +19,12 @@ export default {
|
|||
},
|
||||
computed: {
|
||||
currentUserHasVoted () {
|
||||
return false
|
||||
return this.poll.user_voted
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
onUserVote (poll) {
|
||||
this.poll = poll
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -37,9 +37,14 @@ export default {
|
|||
optionID (index) {
|
||||
return `pollOption${index}`
|
||||
},
|
||||
onChoice (e) {
|
||||
async onChoice (e) {
|
||||
const pollID = this.poll.id
|
||||
const optionName = e.target.value
|
||||
|
||||
this.loading = true
|
||||
console.log(e.target.value)
|
||||
const poll = await this.$store.state.api.backendInteractor.vote(pollID, optionName)
|
||||
this.loading = false
|
||||
this.$emit('user-has-voted', poll)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,7 +3,6 @@ import MediaUpload from '../media_upload/media_upload.vue'
|
|||
import ScopeSelector from '../scope_selector/scope_selector.vue'
|
||||
import EmojiInput from '../emoji-input/emoji-input.vue'
|
||||
import PollForm from '../poll/poll_form/poll_form.vue'
|
||||
import PollIcon from '../poll/poll_icon/poll_icon.vue'
|
||||
import fileTypeService from '../../services/file_type/file_type.service.js'
|
||||
import Completion from '../../services/completion/completion.js'
|
||||
import { take, filter, reject, map, uniqBy } from 'lodash'
|
||||
|
@ -35,7 +34,6 @@ const PostStatusForm = {
|
|||
MediaUpload,
|
||||
EmojiInput,
|
||||
PollForm,
|
||||
PollIcon,
|
||||
ScopeSelector
|
||||
},
|
||||
mounted () {
|
||||
|
|
|
@ -45,6 +45,7 @@ const MASTODON_MUTE_USER_URL = id => `/api/v1/accounts/${id}/mute`
|
|||
const MASTODON_UNMUTE_USER_URL = id => `/api/v1/accounts/${id}/unmute`
|
||||
const MASTODON_POST_STATUS_URL = '/api/v1/statuses'
|
||||
const MASTODON_MEDIA_UPLOAD_URL = '/api/v1/media'
|
||||
const MASTODON_VOTE_URL = '/api/v1/polls/vote'
|
||||
|
||||
import { each, map } from 'lodash'
|
||||
import { parseStatus, parseUser, parseNotification, parseAttachment } from '../entity_normalizer/entity_normalizer.service.js'
|
||||
|
@ -641,6 +642,22 @@ const markNotificationsAsSeen = ({id, credentials}) => {
|
|||
}).then((data) => data.json())
|
||||
}
|
||||
|
||||
const vote = ({pollID, optionName, credentials}) => {
|
||||
const form = new FormData()
|
||||
|
||||
form.append('option_name', optionName)
|
||||
form.append('question_id', pollID)
|
||||
|
||||
return promisedRequest(
|
||||
MASTODON_VOTE_URL,
|
||||
{
|
||||
method: 'PATCH',
|
||||
headers: authHeaders(credentials),
|
||||
body: form
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
const apiService = {
|
||||
verifyCredentials,
|
||||
fetchTimeline,
|
||||
|
@ -683,7 +700,8 @@ const apiService = {
|
|||
approveUser,
|
||||
denyUser,
|
||||
suggestions,
|
||||
markNotificationsAsSeen
|
||||
markNotificationsAsSeen,
|
||||
vote
|
||||
}
|
||||
|
||||
export default apiService
|
||||
|
|
|
@ -58,6 +58,10 @@ const backendInteractorService = (credentials) => {
|
|||
return apiService.denyUser({credentials, id})
|
||||
}
|
||||
|
||||
const vote = (pollID, optionName) => {
|
||||
return apiService.vote({pollID, optionName})
|
||||
}
|
||||
|
||||
const startFetching = ({timeline, store, userId = false, tag}) => {
|
||||
return timelineFetcherService.startFetching({timeline, store, credentials, userId, tag})
|
||||
}
|
||||
|
@ -116,7 +120,8 @@ const backendInteractorService = (credentials) => {
|
|||
changePassword,
|
||||
fetchFollowRequests,
|
||||
approveUser,
|
||||
denyUser
|
||||
denyUser,
|
||||
vote
|
||||
}
|
||||
|
||||
return backendInteractorServiceInstance
|
||||
|
|
Loading…
Reference in a new issue