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 {
|
import {
|
||||||
batch,
|
batch,
|
||||||
createRenderEffect,
|
|
||||||
createSelector,
|
createSelector,
|
||||||
createSignal,
|
createSignal,
|
||||||
Index,
|
Index,
|
||||||
|
@ -173,6 +172,7 @@ const TootPoll: Component<TootPollProps> = (props) => {
|
||||||
<TootPollDialog
|
<TootPollDialog
|
||||||
open={showVoteDialog()}
|
open={showVoteDialog()}
|
||||||
options={poll().options}
|
options={poll().options}
|
||||||
|
multiple={poll().multiple}
|
||||||
onVote={[vote, props.status]}
|
onVote={[vote, props.status]}
|
||||||
onClose={() => setShowVoteDialog(false)}
|
onClose={() => setShowVoteDialog(false)}
|
||||||
initialVotes={[initialVote()]}
|
initialVotes={[initialVote()]}
|
||||||
|
|
|
@ -9,7 +9,6 @@ import {
|
||||||
import type { mastodon } from "masto";
|
import type { mastodon } from "masto";
|
||||||
import {
|
import {
|
||||||
createEffect,
|
createEffect,
|
||||||
createRenderEffect,
|
|
||||||
createSignal,
|
createSignal,
|
||||||
Index,
|
Index,
|
||||||
Show,
|
Show,
|
||||||
|
@ -47,7 +46,10 @@ const TootPollDialog: Component<TootPollDialogPoll> = (props) => {
|
||||||
|
|
||||||
const toggleVote = (i: number) => {
|
const toggleVote = (i: number) => {
|
||||||
if (props.multiple) {
|
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 {
|
} else {
|
||||||
setVotes([i]);
|
setVotes([i]);
|
||||||
}
|
}
|
||||||
|
@ -56,7 +58,8 @@ const TootPollDialog: Component<TootPollDialogPoll> = (props) => {
|
||||||
const sendVote = async () => {
|
const sendVote = async () => {
|
||||||
setInProgress(true);
|
setInProgress(true);
|
||||||
try {
|
try {
|
||||||
await props.onVote[0](props.onVote[1], votes());
|
const [callback, status] = props.onVote;
|
||||||
|
await callback(status, votes());
|
||||||
} catch (reason) {
|
} catch (reason) {
|
||||||
console.error(reason);
|
console.error(reason);
|
||||||
props.onClose?.("cancel");
|
props.onClose?.("cancel");
|
||||||
|
|
Loading…
Add table
Reference in a new issue