import { useEffect, useRef } from "react" import { useSuspenseQuery } from "@tanstack/react-query" import { createFileRoute, Link } from "@tanstack/react-router" import { ArrowLeftIcon, ExternalLinkIcon } from "lucide-react" import { toast } from "sonner" import type { ItemDetail, ThreadEntry } from "@workspace/types" import { Button } from "@workspace/ui/components/button" import { cn } from "@workspace/ui/lib/utils" import { AccountLink, ReportText } from "@/components/account-link" import { ItemBadges } from "@/components/item-badges" import { AgentMessage } from "@/components/thread/agent-message" import { Composer } from "@/components/thread/composer" import { FixPanel } from "@/components/thread/fix-panel" import { TakedownCard } from "@/components/thread/takedown-card" import { TriageLine } from "@/components/thread/triage-line" import { itemQuery, useItemAction } from "@/lib/api" import { cost, when } from "@/lib/format" export const Route = createFileRoute("/items/$id")({ params: { parse: (p) => ({ id: Number(p.id) }), stringify: (p) => ({ id: String(p.id) }), }, loader: ({ context, params }) => context.queryClient.ensureQueryData(itemQuery(params.id)), component: ItemPage, errorComponent: ({ error }) =>

{error instanceof Error ? error.message : String(error)}

, }) function Post({ item }: { item: ItemDetail }) { return (
{item.source === "bluesky" ? `@${item.author} on Bluesky` : item.source === "classifier" ? `Filed by the ${item.author} classifier` : "In-app report"} {item.reporter && ( <> {" "} by )}{" "} ยท {when(item.receivedAt)} open
{item.subject && (
)} {item.images.length > 0 && (
{item.images.map((src) => ( Attached to the post ))}
)}
) } function Entry({ entry }: { entry: ThreadEntry }) { if (entry.kind === "event") { return (

{entry.tone === "live" && } {entry.text}

) } if (entry.kind === "user") { return (
You
{entry.text}
) } return } function ItemPage() { const { id } = Route.useParams() const { data: item } = useSuspenseQuery(itemQuery(id)) const act = useItemAction(id) const bottom = useRef(null) const length = item.thread.length + (item.fix ? 1 : 0) // Open at the latest message, like a chat. useEffect(() => { bottom.current?.scrollIntoView({ block: "end" }) }, [id]) // Follow the conversation as it grows, unless the reader has scrolled up. useEffect(() => { const nearBottom = window.innerHeight + window.scrollY >= document.body.scrollHeight - 240 if (nearBottom) bottom.current?.scrollIntoView({ block: "end" }) }, [length]) const action = (name: "investigate" | "done" | "dismiss", label: string) => ( ) return (
{!item.hasSession && item.status !== "investigate" && item.status !== "investigating" && action("investigate", "Investigate")} {item.status !== "done" && action("done", "Mark done")} {item.status !== "dismissed" && action("dismiss", "Dismiss")}

#{item.id}

{item.cost > 0 && {cost(item.cost)}}
{item.thread.map((entry, i) => ( ))} {item.fix && }
) }