import { cn } from "@/commons"; import { settingsQueryOptions } from "@/routes/__root"; import { useSuspenseQuery } from "@tanstack/react-query"; import { nanoid } from "nanoid"; import { type ReactNode, useMemo, useState } from "react"; import reactStringReplace from "react-string-replace"; import { Hashtag } from "./mentions/hashtag"; import { MentionNote } from "./mentions/note"; import { MentionUser } from "./mentions/user"; import { Images } from "./preview/images"; import { useNoteContext } from "./provider"; export function NoteContent({ quote = true, mention = true, clean, className, }: { quote?: boolean; mention?: boolean; clean?: boolean; className?: string; }) { const event = useNoteContext(); const settings = useSuspenseQuery(settingsQueryOptions); const content = useMemo(() => { try { // Get parsed meta const { content, hashtags, events, mentions } = event.meta; // Define rich content let richContent: ReactNode[] | string = settings.data.display_media ? content : event.content; for (const hashtag of hashtags) { const regex = new RegExp(`(|^)${hashtag}\\b`, "g"); richContent = reactStringReplace(richContent, regex, (_, index) => { return ; }); } for (const event of events) { if (quote) { richContent = reactStringReplace(richContent, event, (_, index) => ( )); } if (!quote && clean) { richContent = reactStringReplace(richContent, event, () => null); } } for (const user of mentions) { if (mention) { richContent = reactStringReplace(richContent, user, (_, index) => ( )); } if (!mention && clean) { richContent = reactStringReplace(richContent, user, () => null); } } richContent = reactStringReplace( richContent, /(https?:\/\/\S+)/gi, (match, index) => ( {match} ), ); richContent = reactStringReplace(richContent, /(\r\n|\r|\n)+/g, () => (
)); return richContent; } catch { return event.content; } }, [event.content]); const [blurred, setBlurred] = useState(() => event.warning ? event.warning.length > 0 : false, ); return (
{!blurred ? ( <>
{content}
{settings.data.display_media ? ( event.meta?.images.length ? ( ) : null ) : null} ) : (

The content is hidden because the author marked it with a warning for a reason: {event.warning}

)}
); }