fix #54: support multi-select polls
All checks were successful
/ depoly (push) Successful in 1m25s

This commit is contained in:
thislight 2025-01-04 20:58:42 +08:00
parent 1f77da4dbe
commit 45c03f9fce
No known key found for this signature in database
GPG key ID: FCFE5192241CCD4E
2 changed files with 7 additions and 4 deletions

View file

@ -1,6 +1,5 @@
import {
batch,
createRenderEffect,
createSelector,
createSignal,
Index,
@ -173,6 +172,7 @@ const TootPoll: Component<TootPollProps> = (props) => {
<TootPollDialog
open={showVoteDialog()}
options={poll().options}
multiple={poll().multiple}
onVote={[vote, props.status]}
onClose={() => setShowVoteDialog(false)}
initialVotes={[initialVote()]}

View file

@ -9,7 +9,6 @@ import {
import type { mastodon } from "masto";
import {
createEffect,
createRenderEffect,
createSignal,
Index,
Show,
@ -47,7 +46,10 @@ const TootPollDialog: Component<TootPollDialogPoll> = (props) => {
const toggleVote = (i: number) => {
if (props.multiple) {
setVotes((o) => [...o.filter((x) => x === i), i]);
setVotes((o) => {
const others = o.filter((x) => x !== i);
return others.length !== o.length ? others : [...others, i];
});
} else {
setVotes([i]);
}
@ -56,7 +58,8 @@ const TootPollDialog: Component<TootPollDialogPoll> = (props) => {
const sendVote = async () => {
setInProgress(true);
try {
await props.onVote[0](props.onVote[1], votes());
const [callback, status] = props.onVote;
await callback(status, votes());
} catch (reason) {
console.error(reason);
props.onClose?.("cancel");