import { Ago, Badge, Banner, Button, InputArea, LayerCard } from "@refs/design-system"; import { ArrowCounterClockwiseIcon, CheckCircleIcon } from "@refs/design-system/icons"; import type { Attribution, LineRange, MentionState, OnlineAgent, ReviewThread, TimelineItem } from "@refs/backend/contract"; import { useEffect, useState } from "react"; import { Link, useFetcher } from "react-router"; import { MentionStates, MentionTools } from "./mentions"; import { useOnSuccess } from "./use-on-success"; import { actorName } from "./attribution"; import { ActorMark, ActorName } from "./timeline"; export type ThreadComment = Extract; export function rangeLabel(range: LineRange): string { const label = (side: LineRange["side"], line: number) => `${side === "deletions" ? "L" : "R"}${line}`; return range.start === range.end && range.side === range.endSide ? label(range.side, range.start) : `${label(range.side, range.start)}–${label(range.endSide, range.end)}`; } function StatusBadge({ thread, now }: { thread: ReviewThread; now: number }) { if (thread.status === "resolved") return Resolved{thread.resolved && <> by {actorName(thread.resolved.by)} }; if (thread.status === "addressed") return ( {thread.addressed ? `${actorName(thread.addressed.by)} says ${thread.addressed.commit.slice(0, 7)} addresses this` : "Addressed"} · awaiting confirmation ); return Open; } /** * A review thread: the lines or decision it is about, its comments, a reply box, and, for people with write access, * Resolve or Reopen. Posts `thread-reply`, `thread-resolve` and `thread-reopen` to the current route. */ export function ReviewThreadCard({ thread, comments, pullBase, agents, canResolve, mentionsOf, now, }: { thread: ReviewThread; comments: readonly ThreadComment[]; pullBase: string; agents: readonly OnlineAgent[]; canResolve: boolean; mentionsOf: (comment: string) => readonly MentionState[]; now: number; }) { const fetcher = useFetcher<{ intent: string; error: string | null }>(); const [body, setBody] = useState(""); const [round, setRound] = useState(0); const [open, setOpen] = useState(thread.status !== "resolved"); const busy = fetcher.state !== "idle"; useOnSuccess(fetcher, (answer) => { if (answer.intent !== "thread-reply") return; setBody(""); setRound((value) => value + 1); }); useEffect(() => setOpen(thread.status !== "resolved"), [thread.status]); return ( {thread.range ? `${thread.path}:${rangeLabel(thread.range)}` : `Decision ${thread.decision}`} {thread.outdated && Outdated} {thread.status === "resolved" && ( )} {open && ( {thread.range ? (
{thread.code}
) : (

{thread.code}

)} {comments.map((comment) => (

))} {body && } {fetcher.data?.error && }
{canResolve && thread.status !== "resolved" && ( )} {canResolve && thread.status !== "open" && ( )}
)}
); }