From ad56f4230da2a434dbcd233d460f10311f1d02d0 Mon Sep 17 00:00:00 2001 From: Xylight Date: Sat, 6 Dec 2025 16:32:13 -0800 Subject: [PATCH] fix: post polls causing scroll to top --- src/lib/feature/post/media/PostPoll.svelte | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/src/lib/feature/post/media/PostPoll.svelte b/src/lib/feature/post/media/PostPoll.svelte index 37790b86..cb391146 100644 --- a/src/lib/feature/post/media/PostPoll.svelte +++ b/src/lib/feature/post/media/PostPoll.svelte @@ -33,12 +33,15 @@ (post.poll.my_votes?.length ?? 0) > 0 ), ) - let chosen = $state(canVote ? undefined : -1) + let chosen = $state(canVote ? undefined : -1) let options = $derived( post.poll.choices.map((i) => ({ ...i, - num_votes: chosen == i.id ? i.num_votes + 1 : i.num_votes, + num_votes: + (typeof chosen !== 'number' && chosen?.includes(i.id)) || chosen == i.id + ? i.num_votes + 1 + : i.num_votes, })), ) let totalVotes = $derived(options.reduce((a, b) => a + b.num_votes, 0)) @@ -52,7 +55,7 @@ loading = true - if (typeof id !== 'number') chosen = id[0] + if (typeof id !== 'number') chosen = id else chosen = id canVote = false @@ -82,7 +85,13 @@ } -
castVote(selected!)}> + { + e.preventDefault() + castVote(selected!) + }} +> {#each options.toSorted((a, b) => a.sort_order - b.sort_order) as choice} {@const active =