pinafore/src/routes/_actions/polls.js
Nolan Lawson 16e66346d7
fix!: remove esm package, use native Node ES modules (#2064)
BREAKING CHANGE: Node v12.20+, v14.14+, or v16.0+ is required

* fix!: remove esm package, use native Node ES modules

* fix: fix some CJS imports
2021-07-04 20:19:04 -07:00

27 lines
952 B
JavaScript

import { getPoll as getPollApi, voteOnPoll as voteOnPollApi } from '../_api/polls.js'
import { store } from '../_store/store.js'
import { toast } from '../_components/toast/toast.js'
import { formatIntl } from '../_utils/formatIntl.js'
export async function getPoll (pollId) {
const { currentInstance, accessToken } = store.get()
try {
const poll = await getPollApi(currentInstance, accessToken, pollId)
return poll
} catch (e) {
console.error(e)
/* no await */ toast.say(formatIntl('intl.unableToRefreshPoll', { error: (e.message || '') }))
}
}
export async function voteOnPoll (pollId, choices) {
const { currentInstance, accessToken } = store.get()
try {
const poll = await voteOnPollApi(currentInstance, accessToken, pollId, choices.map(_ => _.toString()))
return poll
} catch (e) {
console.error(e)
/* no await */ toast.say(formatIntl('intl.unableToVoteInPoll', { error: (e.message || '') }))
}
}