RegularToot: supports polls

This commit is contained in:
thislight 2024-11-23 20:55:37 +08:00
parent 9bf957188c
commit c85cffc03e
No known key found for this signature in database
GPG key ID: FCFE5192241CCD4E
6 changed files with 408 additions and 2 deletions

View file

@ -232,6 +232,40 @@ const TootList: Component<{
openFullScreenToot(status, element, true);
};
const vote = async ({
status,
votes,
}: {
status: mastodon.v1.Status;
votes: readonly number[];
}) => {
const client = session()?.client;
if (!client) return;
const toot = status.reblog ?? status;
if (!toot.poll) return;
const npoll = await client.v1.polls.$select(toot.poll.id).votes.create({
choices: votes,
});
if (status.reblog) {
props.onChangeToot(status.id, {
...status,
reblog: {
...status.reblog,
poll: npoll,
},
});
} else {
props.onChangeToot(status.id, {
...status,
poll: npoll,
});
}
};
return (
<ErrorBoundary
fallback={(err, reset) => {
@ -272,6 +306,7 @@ const TootList: Component<{
onRetoot={toggleBoost}
onFavourite={toggleFavourite}
onReply={reply}
onVote={vote}
onClick={[onItemClick, status()]}
/>
);