From 75047e878b1848dcc7329783826e0a5a0dee3fbe Mon Sep 17 00:00:00 2001 From: Daniel Roe Date: Wed, 28 Dec 2022 12:49:47 +0100 Subject: [PATCH] fix: update cache with poll votes (#598) --- components/status/StatusContent.vue | 5 +---- components/status/StatusPoll.vue | 12 +++++++----- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/components/status/StatusContent.vue b/components/status/StatusContent.vue index 262d7887..98f15c2e 100644 --- a/components/status/StatusContent.vue +++ b/components/status/StatusContent.vue @@ -34,10 +34,7 @@ const isFiltered = $computed(() => filterPhrase && (context && context !== 'deta

{{ status.spoilerText || `${$t('status.filter_hidden_phrase')}: ${filterPhrase}` }}

- + -import type { Poll } from 'masto' +import type { Status } from 'masto' -const { poll: _poll } = defineProps<{ - poll: Poll +const { status } = defineProps<{ + status: Status }>() -const poll = reactive({ ..._poll }) +const poll = reactive({ ...status.poll! }) function toPercentage(num: number) { const percentage = 100 * num @@ -19,7 +19,6 @@ const masto = useMasto() async function vote(e: Event) { const formData = new FormData(e.target as HTMLFormElement) const choices = formData.getAll('choices') as string[] - await masto.poll.vote(poll.id, { choices }) // Update the poll optimistically for (const [index, option] of poll.options.entries()) { @@ -29,6 +28,9 @@ async function vote(e: Event) { poll.voted = true poll.votesCount++ poll.votersCount = (poll.votersCount || 0) + 1 + cacheStatus({ ...status, poll }, undefined, true) + + await masto.poll.vote(poll.id, { choices }) }