The best way to control Claude Code, Codex and more from any computer or phone

main
tsx 112 lines 3.09 KB
Raw
1 import type { PullRequestReviewGuideStop } from "@t3tools/contracts";
2 import { T, useGT, useMessages } from "gt-react";
3 import { CheckIcon } from "lucide-react";
4
5 import { cn } from "~/lib/utils";
6
7 import { Badge } from "../../ui/badge";
8 import { stopSubline } from "@t3tools/client-runtime/review-guide-tour";
9
10 export function GuideRail({
11 stops,
12 position,
13 seen,
14 onSelect,
15 }: {
16 stops: ReadonlyArray<PullRequestReviewGuideStop>;
17 position: number;
18 seen: ReadonlySet<number>;
19 onSelect: (position: number) => void;
20 }) {
21 const gt = useGT();
22 const messages = useMessages();
23 const reviewed = seen.size;
24 const renderStop = (stop: PullRequestReviewGuideStop, index: number) => (
25 <li key={index}>
26 <RailRow
27 active={position === index}
28 onClick={() => onSelect(index)}
29 lead={<StopBullet number={index + 1} seen={seen.has(index)} />}
30 title={stop.title}
31 detail={
32 <>
33 {stop.attention !== null ? (
34 <Badge size="sm" variant="warning">
35 <T>Look closely</T>
36 </Badge>
37 ) : null}
38 <span>{stopSubline(stop, messages)}</span>
39 </>
40 }
41 />
42 </li>
43 );
44
45 return (
46 <nav aria-label={gt("Review tour")} className="flex min-h-0 flex-col gap-4">
47 <p className="text-xs text-muted-foreground tabular-nums @max-[56rem]/guide:hidden">
48 {gt(
49 "{total, plural, one {{reviewed} of {total} read} other {{reviewed} of {total} read}}",
50 { reviewed, total: stops.length },
51 )}
52 </p>
53 <div className="flex flex-col gap-4">
54 <ol className="flex flex-col gap-0.5">{stops.map(renderStop)}</ol>
55 </div>
56 </nav>
57 );
58 }
59
60 function RailRow({
61 active,
62 onClick,
63 lead,
64 title,
65 detail,
66 }: {
67 active: boolean;
68 onClick: () => void;
69 lead: React.ReactNode;
70 title: string;
71 detail: React.ReactNode;
72 }) {
73 return (
74 <button
75 type="button"
76 aria-current={active ? "step" : undefined}
77 onClick={onClick}
78 className={cn(
79 "flex w-full items-start gap-2 rounded-md px-2 py-1.5 text-left outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-inset",
80 active ? "bg-accent text-accent-foreground" : "hover:bg-accent/50",
81 )}
82 >
83 {lead}
84 <span className="flex min-w-0 flex-col gap-0.5">
85 <span className="text-sm text-foreground">{title}</span>
86 {detail !== null ? (
87 <span className="flex flex-wrap items-center gap-1.5 text-xs text-muted-foreground">
88 {detail}
89 </span>
90 ) : null}
91 </span>
92 </button>
93 );
94 }
95
96 function StopBullet({ number, seen }: { number: number; seen: boolean }) {
97 const gt = useGT();
98 return (
99 <span
100 className={cn(
101 "flex size-5 shrink-0 items-center justify-center rounded-full border text-2xs tabular-nums",
102 seen ? "border-success/40 text-success-foreground" : "border-border text-muted-foreground",
103 )}
104 >
105 {seen ? (
106 <CheckIcon aria-label={gt("Stop {number}, read", { number })} className="size-3" />
107 ) : (
108 number
109 )}
110 </span>
111 );
112 }