diff --git a/src/routes/_actions/polls.js b/src/routes/_actions/polls.js index 612b8778..b4195815 100644 --- a/src/routes/_actions/polls.js +++ b/src/routes/_actions/polls.js @@ -1,4 +1,4 @@ -import { getPoll as getPollApi } from '../_api/polls' +import { getPoll as getPollApi, voteOnPoll as voteOnPollApi } from '../_api/polls' import { store } from '../_store/store' import { toast } from '../_components/toast/toast' @@ -9,6 +9,17 @@ export async function getPoll (pollId) { return poll } catch (e) { console.error(e) - toast.say(`Unable to refresh poll`) + toast.say('Unable to refresh poll: ' + (e.message || '')) + } +} + +export async function voteOnPoll (pollId, choices) { + let { currentInstance, accessToken } = store.get() + try { + let 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 || '')) } } diff --git a/src/routes/_api/polls.js b/src/routes/_api/polls.js index 5610666d..f3cd5aed 100644 --- a/src/routes/_api/polls.js +++ b/src/routes/_api/polls.js @@ -1,7 +1,12 @@ -import { get, DEFAULT_TIMEOUT } from '../_utils/ajax' +import { get, post, DEFAULT_TIMEOUT, WRITE_TIMEOUT } from '../_utils/ajax' import { auth, basename } from './utils' export async function getPoll (instanceName, accessToken, pollId) { let url = `${basename(instanceName)}/api/v1/polls/${pollId}` return get(url, auth(accessToken), { timeout: DEFAULT_TIMEOUT }) } + +export async function voteOnPoll (instanceName, accessToken, pollId, choices) { + let url = `${basename(instanceName)}/api/v1/polls/${pollId}/votes` + return post(url, { choices }, auth(accessToken), { timeout: WRITE_TIMEOUT }) +} diff --git a/src/routes/_components/status/Status.html b/src/routes/_components/status/Status.html index d8929120..853ff8f6 100644 --- a/src/routes/_components/status/Status.html +++ b/src/routes/_components/status/Status.html @@ -144,7 +144,7 @@ import { createStatusOrNotificationUuid } from '../../_utils/createStatusOrNotificationUuid' import { statusHtmlToPlainText } from '../../_utils/statusHtmlToPlainText' - const INPUT_TAGS = new Set(['a', 'button', 'input', 'textarea']) + const INPUT_TAGS = new Set(['a', 'button', 'input', 'textarea', 'label']) const isUserInputElement = node => INPUT_TAGS.has(node.localName) const isToolbar = node => node.classList.contains('status-toolbar') const isStatusArticle = node => node.classList.contains('status-article') diff --git a/src/routes/_components/status/StatusPoll.html b/src/routes/_components/status/StatusPoll.html index 67f7dea6..b1a8acca 100644 --- a/src/routes/_components/status/StatusPoll.html +++ b/src/routes/_components/status/StatusPoll.html @@ -1,16 +1,35 @@ -