From 737d63f88a98d443d8208a9700c9a8845a4854e0 Mon Sep 17 00:00:00 2001 From: thislight Date: Wed, 20 Nov 2024 16:24:57 +0800 Subject: [PATCH] RegularToot: support content warning --- src/timelines/RegularToot.tsx | 12 ++++ src/timelines/toot-components/TootContent.css | 4 ++ src/timelines/toot-components/TootContent.tsx | 59 +++++++++++++++---- 3 files changed, 64 insertions(+), 11 deletions(-) diff --git a/src/timelines/RegularToot.tsx b/src/timelines/RegularToot.tsx index 5a4faa0..bb70372 100644 --- a/src/timelines/RegularToot.tsx +++ b/src/timelines/RegularToot.tsx @@ -5,6 +5,8 @@ import { type JSX, Show, createRenderEffect, + createSignal, + type Setter, } from "solid-js"; import tootStyle from "./toot.module.css"; import { formatRelative } from "date-fns"; @@ -200,6 +202,11 @@ export function findElementActionable( return current; } +function onToggleReveal(setValue: Setter, event: Event) { + event.stopPropagation(); + setValue((x) => !x); +} + /** * Component for a toot. * @@ -239,6 +246,7 @@ const RegularToot: Component = (props) => { const status = () => managed.status; const toot = () => status().reblog ?? status(); const session = useDefaultSession(); + const [reveal, setReveal] = createSignal(false); css` .reply-sep { @@ -326,6 +334,10 @@ const RegularToot: Component = (props) => { emojis={toot().emojis} mentions={toot().mentions} class={cardStyle.cardNoPad} + sensitive={toot().sensitive} + spoilerText={toot().spoilerText} + reveal={reveal()} + onToggleReveal={[onToggleReveal, setReveal]} /> diff --git a/src/timelines/toot-components/TootContent.css b/src/timelines/toot-components/TootContent.css index b5e56e6..79c4ffc 100644 --- a/src/timelines/toot-components/TootContent.css +++ b/src/timelines/toot-components/TootContent.css @@ -4,6 +4,10 @@ margin-right: var(--card-pad, 0); line-height: 1.5; + > .content { + display: contents; + } + & * { user-select: text; } diff --git a/src/timelines/toot-components/TootContent.tsx b/src/timelines/toot-components/TootContent.tsx index fd0dab6..edc3689 100644 --- a/src/timelines/toot-components/TootContent.tsx +++ b/src/timelines/toot-components/TootContent.tsx @@ -5,20 +5,26 @@ import { type JSX, createRenderEffect, createMemo, + Show, } from "solid-js"; import { resolveCustomEmoji } from "../../masto/toot.js"; import { makeAcctText, useDefaultSession } from "../../masto/clients"; import "./TootContent.css"; +import { Button } from "@suid/material"; function preventDefault(event: Event) { event.preventDefault(); } -export type TootContentProps = { +export type TootContentProps = JSX.HTMLAttributes & { source?: string; emojis?: mastodon.v1.CustomEmoji[]; mentions: mastodon.v1.StatusMention[]; -} & JSX.HTMLAttributes; + sensitive?: boolean; + spoilerText?: string; + reveal?: boolean; + onToggleReveal?: JSX.EventHandlerUnion; +}; const TootContent: Component = (oprops) => { const session = useDefaultSession(); @@ -27,23 +33,23 @@ const TootContent: Component = (oprops) => { "emojis", "mentions", "class", + "sensitive", + "spoilerText", + "reveal", + "onToggleReveal", ]); const clientFinder = createMemo(() => session() ? makeAcctText(session()!) : undefined, ); + const shouldRevealContent = () => { + return !props.sensitive || (props.sensitive && props.reveal); + }; + return (
{ - createRenderEffect(() => { - ref.innerHTML = props.source - ? props.emojis - ? resolveCustomEmoji(props.source, props.emojis) - : props.source - : ""; - }); - createRenderEffect(() => { const finder = clientFinder(); for (const mention of props.mentions) { @@ -61,7 +67,38 @@ const TootContent: Component = (oprops) => { }} class={`TootContent ${props.class || ""}`} {...rest} - >
+ > + +
+ { + createRenderEffect(() => { + ref.innerHTML = props.spoilerText + ? props.emojis + ? resolveCustomEmoji(props.spoilerText, props.emojis) + : props.spoilerText + : ""; + }); + }} + > + +
+
+ +
+ createRenderEffect(() => { + ref.innerHTML = props.source + ? props.emojis + ? resolveCustomEmoji(props.source, props.emojis) + : props.source + : ""; + }) + } + >
+
+ ); };