diff --git a/components/status/StatusPoll.vue b/components/status/StatusPoll.vue index d8bcbbf7..b39b5351 100644 --- a/components/status/StatusPoll.vue +++ b/components/status/StatusPoll.vue @@ -14,6 +14,7 @@ const timeAgoOptions = useTimeAgoOptions() const expiredTimeAgo = useTimeAgo(poll.expiresAt!, timeAgoOptions) const expiredTimeFormatted = useFormattedDateTime(poll.expiresAt!) const { formatPercentage } = useHumanReadableNumber() +const loading = ref(false) const { client } = useMasto() @@ -39,6 +40,25 @@ async function vote(e: Event) { await client.value.v1.polls.$select(poll.id).votes.create({ choices }) } +async function refresh() { + if (loading.value) { + return + } + + loading.value = true + try { + const newPoll = await client.value.v1.polls.$select(poll.id).fetch() + Object.assign(poll, newPoll) + cacheStatus({ ...status, poll: newPoll }, undefined, true) + } + catch (e) { + console.error(e) + } + finally { + loading.value = false + } +} + const votersCount = computed(() => poll.votersCount ?? poll.votesCount ?? 0) @@ -71,15 +91,27 @@ const votersCount = computed(() => poll.votersCount ?? poll.votesCount ?? 0) -