RegularToot: refactor, add env context

This commit is contained in:
thislight 2024-11-23 22:21:14 +08:00
parent cbdf5e667d
commit ad7db8e865
No known key found for this signature in database
GPG key ID: FCFE5192241CCD4E
5 changed files with 164 additions and 123 deletions

View file

@ -13,7 +13,10 @@ import { Title } from "~material/typography";
import { Close as CloseIcon } from "@suid/icons-material";
import { useSessionForAcctStr } from "../masto/clients";
import { resolveCustomEmoji } from "../masto/toot";
import RegularToot, { findElementActionable } from "./RegularToot";
import RegularToot, {
findElementActionable,
TootEnvProvider,
} from "./RegularToot";
import type { mastodon } from "masto";
import cards from "~material/cards.module.css";
import { css } from "solid-styled";
@ -169,6 +172,33 @@ const TootBottomSheet: Component = (props) => {
return Array.from(new Set(values).keys());
};
const vote = async (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) {
setRemoteToot({
...status,
reblog: {
...status.reblog,
poll: npoll,
},
});
} else {
setRemoteToot({
...status,
poll: npoll,
});
}
};
const handleMainTootClick = (
event: MouseEvent & { currentTarget: HTMLElement },
) => {
@ -255,23 +285,29 @@ const TootBottomSheet: Component = (props) => {
<article>
<Show when={toot()}>
<RegularToot
id={`toot-${toot()!.id}`}
class={cards.card}
style={{
"scroll-margin-top":
"calc(var(--scaffold-topbar-height) + 20px)",
"cursor": "auto",
"user-select": "auto",
<TootEnvProvider
value={{
bookmark: onBookmark,
boost: onBoost,
favourite: onFav,
vote,
}}
status={toot()!}
actionable={!!actSession()}
evaluated={true}
onBookmark={onBookmark}
onRetoot={onBoost}
onFavourite={onFav}
onClick={handleMainTootClick}
></RegularToot>
>
<RegularToot
id={`toot-${toot()!.id}`}
class={cards.card}
style={{
"scroll-margin-top":
"calc(var(--scaffold-topbar-height) + 20px)",
cursor: "auto",
"user-select": "auto",
}}
status={toot()!}
actionable={!!actSession()}
evaluated={true}
onClick={handleMainTootClick}
></RegularToot>
</TootEnvProvider>
</Show>
</article>