Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

GuideNotes.tsx

64 lines2.1 KB

1import { T, useGT, plural, part } from "gt-react";
2import type { PullRequestReviewGuideNote } from "@t3tools/contracts";
3​
4import { cn } from "~/lib/utils";
5​
6import { GuideProse } from "./GuideProse";
7​
8export function GuideNoteMarker({ marker }: { marker: string }) {
9 return (
10 <span
11 aria-hidden
12 className="inline-flex size-4.5 shrink-0 items-center justify-center rounded-full bg-info/16 font-medium text-3xs text-info-foreground tabular-nums"
13 >
14 {marker}
15 </span>
16 );
18​
19export function GuideNotes({
20 notes,
21 className,
22}: {
23 notes: ReadonlyArray<{ readonly marker: string; readonly note: PullRequestReviewGuideNote }>;
24 className?: string;
25}) {
26 const gt = useGT();
27 if (notes.length === 0) return null;
28 return (
29 <section className={cn("flex min-w-0 flex-col gap-2", className)}>
30 <h4 className="flex items-baseline justify-between gap-2 text-xs font-medium text-foreground">
31 <T>Notes on this stop</T>
32 <span className="font-normal text-muted-foreground tabular-nums">
33 {gt`${plural(
34 { count: notes.length },
35 {
36 one: part`${{ count: notes.length }} note`,
37 other: part`${{ count: notes.length }} notes`,
38 },
39 )}`}
40 </span>
41 </h4>
42 <ol className="flex flex-col gap-3">
43 {notes.map(({ marker, note }) => (
44 <li key={marker} className="flex min-w-0 gap-2">
45 <GuideNoteMarker marker={marker} />
46 <div className="flex min-w-0 flex-col gap-0.5">
47 <p className="flex flex-wrap items-baseline gap-x-2 text-xs">
48 <span className="font-medium text-foreground">{note.title}</span>
49 <span className="truncate font-mono text-2xs text-muted-foreground">
50 {note.path.split("/").at(-1)}:{note.line}
51 </span>
52 </p>
53 {note.body.trim() !== "" ? (
54 <div className="text-xs text-muted-foreground">
55 <GuideProse text={note.body} />
56 </div>
57 ) : null}
58 </div>
59 </li>
60 ))}
61 </ol>
62 </section>
63 );