import type { // TODO ref backend fetching!! Reference, Block, Inline, Media as MediaType, ExternalContent, } from "@/types/trill"; import type { PostProps } from "./Post"; import Media from "./Media"; import JSONContent, { YoutubeSnippet } from "./External"; import { useLocation } from "wouter"; import Quote from "./Quote"; import PostData from "./Loader"; import Card from "./Card.tsx"; import type { Ship } from "@/types/urbit.ts"; import { extractURLs } from "@/logic/nostrill.ts"; function Body(props: PostProps) { const text = props.poast.contents.filter((c) => { return ( "paragraph" in c || "blockquote" in c || "heading" in c || "codeblock" in c || "list" in c ); }); const media: MediaType[] = props.poast.contents.filter( (c): c is MediaType => "media" in c, ); const refs = props.poast.contents.filter((c): c is Reference => "ref" in c); const json = props.poast.contents.filter( (c): c is ExternalContent => "json" in c, ); return (
{text.map((b, i) => ( ))}
{media.length > 0 && } {refs.map((r, i) => ( ))}
); } export default Body; function TextBlock({ block }: { block: Block }) { const key = JSON.stringify(block); return "paragraph" in block ? (
{block.paragraph.map((i, ind) => ( ))}
) : "blockquote" in block ? (
{block.blockquote.map((i, ind) => ( ))}
) : "heading" in block ? ( ) : "codeblock" in block ? (
      
        {block.codeblock.code}
      
    
) : "list" in block ? ( block.list.ordered ? (
    {block.list.text.map((i, ind) => (
  1. ))}
) : ( ) ) : null; } function Inlin({ i }: { i: Inline }) { const [_, navigate] = useLocation(); function gotoShip(e: React.MouseEvent, ship: Ship) { e.stopPropagation(); navigate(`/feed/${ship}`); } if ("text" in i) { const tokens = extractURLs(i.text); return ( <> {tokens.text.map((t, i) => "text" in t ? ( {t.text} ) : ( {t.link.show} ), )} {tokens.pics.map((p, i) => ( ))} {tokens.vids.map((p, i) => (