From 45c03f9fcedd462a3fc198b850c5b31a7f97e0d8 Mon Sep 17 00:00:00 2001 From: thislight Date: Sat, 4 Jan 2025 20:58:42 +0800 Subject: [PATCH] fix #54: support multi-select polls --- src/timelines/toots/TootPoll.tsx | 2 +- src/timelines/toots/TootPollDialog.tsx | 9 ++++++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/timelines/toots/TootPoll.tsx b/src/timelines/toots/TootPoll.tsx index 5c08c21..42cbdd5 100644 --- a/src/timelines/toots/TootPoll.tsx +++ b/src/timelines/toots/TootPoll.tsx @@ -1,6 +1,5 @@ import { batch, - createRenderEffect, createSelector, createSignal, Index, @@ -173,6 +172,7 @@ const TootPoll: Component = (props) => { setShowVoteDialog(false)} initialVotes={[initialVote()]} diff --git a/src/timelines/toots/TootPollDialog.tsx b/src/timelines/toots/TootPollDialog.tsx index f63d204..581fd6f 100644 --- a/src/timelines/toots/TootPollDialog.tsx +++ b/src/timelines/toots/TootPollDialog.tsx @@ -9,7 +9,6 @@ import { import type { mastodon } from "masto"; import { createEffect, - createRenderEffect, createSignal, Index, Show, @@ -47,7 +46,10 @@ const TootPollDialog: Component = (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 = (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");