fix #54: support multi-select polls
All checks were successful
/ depoly (push) Successful in 1m25s
All checks were successful
/ depoly (push) Successful in 1m25s
This commit is contained in:
parent
1f77da4dbe
commit
45c03f9fce
2 changed files with 7 additions and 4 deletions
|
@ -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()]}
|
||||
|
|
|
@ -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");
|
||||
|
|
Loading…
Add table
Reference in a new issue