Skip to content

Commit 75047e8

Browse files
authored
fix: update cache with poll votes (#598)
1 parent 15fee71 commit 75047e8

File tree

2 files changed

+8
-9
lines changed

2 files changed

+8
-9
lines changed

components/status/StatusContent.vue

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,7 @@ const isFiltered = $computed(() => filterPhrase && (context && context !== 'deta
3434
<p>{{ status.spoilerText || `${$t('status.filter_hidden_phrase')}: ${filterPhrase}` }}</p>
3535
</template>
3636
<StatusBody :status="status" :with-action="!isDetails" :class="isDetails ? 'text-xl' : ''" />
37-
<StatusPoll
38-
v-if="status.poll"
39-
:poll="status.poll"
40-
/>
37+
<StatusPoll v-if="status.poll" :status="status" />
4138
<StatusMedia
4239
v-if="status.mediaAttachments?.length"
4340
:status="status"

components/status/StatusPoll.vue

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
<script setup lang="ts">
2-
import type { Poll } from 'masto'
2+
import type { Status } from 'masto'
33
4-
const { poll: _poll } = defineProps<{
5-
poll: Poll
4+
const { status } = defineProps<{
5+
status: Status
66
}>()
7-
const poll = reactive({ ..._poll })
7+
const poll = reactive({ ...status.poll! })
88
99
function toPercentage(num: number) {
1010
const percentage = 100 * num
@@ -19,7 +19,6 @@ const masto = useMasto()
1919
async function vote(e: Event) {
2020
const formData = new FormData(e.target as HTMLFormElement)
2121
const choices = formData.getAll('choices') as string[]
22-
await masto.poll.vote(poll.id, { choices })
2322
2423
// Update the poll optimistically
2524
for (const [index, option] of poll.options.entries()) {
@@ -29,6 +28,9 @@ async function vote(e: Event) {
2928
poll.voted = true
3029
poll.votesCount++
3130
poll.votersCount = (poll.votersCount || 0) + 1
31+
cacheStatus({ ...status, poll }, undefined, true)
32+
33+
await masto.poll.vote(poll.id, { choices })
3234
}
3335
</script>
3436

0 commit comments

Comments
 (0)