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