import type { ReactNode } from "react" import { ExternalLinkIcon } from "lucide-react" import type { Account, ItemSummary } from "@workspace/types" /** * A link that opens in a new tab. * * Inside a queue card, which is itself a link, a nested anchor is not allowed, * so there it opens from a click instead. */ export function OutLink({ href, inCard = false, children }: { href: string; inCard?: boolean; children: ReactNode }) { const className = "hover:underline inline-flex min-w-0 items-center gap-1.5" if (inCard) { const open = (e: React.SyntheticEvent) => { e.preventDefault() e.stopPropagation() window.open(href, "_blank", "noopener,noreferrer") } return ( e.key === "Enter" && open(e)}> {children} ) } return ( {children} ) } /** An account on grain, linked to its profile there. */ export function AccountLink({ account, inCard = false }: { account: Account; inCard?: boolean }) { return ( {account.handle ? `@${account.handle}` : account.did} {account.displayName && {account.displayName}} ) } const IMAGE = /^Image: (https:\/\/cdn\.bsky\.app\/img\/\S+)$/ /** * A report's text with its "Subject:" line linked to the subject on grain.social * and a photo's "Image:" line linked to the image. Those two lines are written * by the poller, never by the reporter, so only their exact shapes are linked. */ export function ReportText({ item, inCard = false, className }: { item: ItemSummary; inCard?: boolean; className?: string }) { if (item.source === "bluesky" || !item.subjectLink) return

{item.text}

const link = item.subjectLink const lines = item.text.split("\n") const subjectLine = lines.findIndex((line) => line.startsWith("Subject: ")) return (

{lines.map((line, i) => { const image = item.source === "classifier" ? line.match(IMAGE) : null let content: ReactNode = line if (i === subjectLine) { content = ( <> Subject:{" "} {link.label} ) } else if (image) { content = ( <> Image:{" "} open the image ) } return ( {i > 0 && "\n"} {content} ) })}

) }