Coves frontend - a photon fork

fix: post polls causing scroll to top

Xylight ad56f423 bacce3dd

+13 -4
+13 -4
src/lib/feature/post/media/PostPoll.svelte
··· 33 33 (post.poll.my_votes?.length ?? 0) > 0 34 34 ), 35 35 ) 36 - let chosen = $state<number | undefined>(canVote ? undefined : -1) 36 + let chosen = $state<number | number[] | undefined>(canVote ? undefined : -1) 37 37 38 38 let options = $derived( 39 39 post.poll.choices.map((i) => ({ 40 40 ...i, 41 - num_votes: chosen == i.id ? i.num_votes + 1 : i.num_votes, 41 + num_votes: 42 + (typeof chosen !== 'number' && chosen?.includes(i.id)) || chosen == i.id 43 + ? i.num_votes + 1 44 + : i.num_votes, 42 45 })), 43 46 ) 44 47 let totalVotes = $derived(options.reduce((a, b) => a + b.num_votes, 0)) ··· 52 55 53 56 loading = true 54 57 55 - if (typeof id !== 'number') chosen = id[0] 58 + if (typeof id !== 'number') chosen = id 56 59 else chosen = id 57 60 58 61 canVote = false ··· 82 85 } 83 86 </script> 84 87 85 - <form class="space-y-2" onsubmit={() => castVote(selected!)}> 88 + <form 89 + class="space-y-2" 90 + onsubmit={(e) => { 91 + e.preventDefault() 92 + castVote(selected!) 93 + }} 94 + > 86 95 <CommonList class=""> 87 96 {#each options.toSorted((a, b) => a.sort_order - b.sort_order) as choice} 88 97 {@const active =