RegularToot: refactor, add env context
This commit is contained in:
parent
cbdf5e667d
commit
ad7db8e865
5 changed files with 164 additions and 123 deletions
|
@ -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>
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue