Pinafore-Web-Client-Frontend/src/routes/_actions/polls.js

26 lines
817 B
JavaScript
Raw Normal View History

import { getPoll as getPollApi, voteOnPoll as voteOnPollApi } from '../_api/polls'
import { store } from '../_store/store'
import { toast } from '../_components/toast/toast'
export async function getPoll (pollId) {
2019-08-03 22:49:37 +02:00
const { currentInstance, accessToken } = store.get()
try {
2019-08-03 22:49:37 +02:00
const poll = await getPollApi(currentInstance, accessToken, pollId)
return poll
} catch (e) {
console.error(e)
toast.say('Unable to refresh poll: ' + (e.message || ''))
}
}
export async function voteOnPoll (pollId, choices) {
2019-08-03 22:49:37 +02:00
const { currentInstance, accessToken } = store.get()
try {
2019-08-03 22:49:37 +02:00
const poll = await voteOnPollApi(currentInstance, accessToken, pollId, choices.map(_ => _.toString()))
return poll
} catch (e) {
console.error(e)
toast.say('Unable to vote in poll: ' + (e.message || ''))
}
}