tangled
alpha
login
or
join now
bretton.dev
/
coves-frontend
1
fork
atom
Coves frontend - a photon fork
1
fork
atom
overview
issues
pulls
pipelines
fix: post polls causing scroll to top
Xylight
4 months ago
ad56f423
bacce3dd
+13
-4
1 changed file
expand all
collapse all
unified
split
src
lib
feature
post
media
PostPoll.svelte
+13
-4
src/lib/feature/post/media/PostPoll.svelte
reviewed
···
33
33
(post.poll.my_votes?.length ?? 0) > 0
34
34
),
35
35
)
36
36
-
let chosen = $state<number | undefined>(canVote ? undefined : -1)
36
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
41
-
num_votes: chosen == i.id ? i.num_votes + 1 : i.num_votes,
41
41
+
num_votes:
42
42
+
(typeof chosen !== 'number' && chosen?.includes(i.id)) || chosen == i.id
43
43
+
? i.num_votes + 1
44
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
55
-
if (typeof id !== 'number') chosen = id[0]
58
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
85
-
<form class="space-y-2" onsubmit={() => castVote(selected!)}>
88
88
+
<form
89
89
+
class="space-y-2"
90
90
+
onsubmit={(e) => {
91
91
+
e.preventDefault()
92
92
+
castVote(selected!)
93
93
+
}}
94
94
+
>
86
95
<CommonList class="">
87
96
{#each options.toSorted((a, b) => a.sort_order - b.sort_order) as choice}
88
97
{@const active =