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

PullRequestGhosts.tsx

330 lines12.2 KB

1/**
2 * Loading states specific to the pull request surface — the first list, a search under way,
3 * and a detail panel opening — use bars in the geometry of the content they stand for, pulsing
4 * on one composited layer. Diff loading uses the shared diff-panel skeleton instead.
5 *
6 * The bars share the app-wide `Skeleton` tone (`muted-foreground` at low alpha, which reads on
7 * both themes) and the single `animate-skeleton` pulse, applied once on the container so any
8 * number of bars costs one opacity animation.
9 */
10import type { PullRequestListEntry } from "@t3tools/contracts";
11import { ArrowLeftIcon } from "lucide-react";
12​
13import { cn } from "~/lib/utils";
14import { formatRelativeTimeLabel } from "~/timestampFormat";
15​
16import { pullRequestLabelColor } from "./pullRequestList.logic";
17import {
18 PullRequestActorLabel,
19 PullRequestDiffStat,
20 pullRequestChecksStatePresentation,
21 resolvePullRequestState,
22} from "./pullRequestPresentation";
23​
24function GhostBar({ className }: { className?: string | undefined }) {
25 return <div aria-hidden className={cn("h-3 rounded bg-muted-foreground/15", className)} />;
27​
28/** Widths cycle rather than randomize, so the ghost renders the same on every pass. */
29const TITLE_WIDTHS = ["w-3/5", "w-2/5", "w-1/2", "w-2/3", "w-2/5", "w-3/5", "w-1/2"];
30const META_WIDTHS = ["w-2/5", "w-1/3", "w-2/5", "w-1/4", "w-1/3", "w-2/5", "w-1/3"];
31​
32/** Rows in the list's own grid — glyph, title over meta, time over diffstat. */
33export function PullRequestListGhost({
34 rows = 7,
35 caption,
36}: {
37 rows?: number;
38 /** Said where the group headers speak, for the states with something to say — a search. */
39 caption?: string;
40}) {
41 return (
42 <div
43 role="status"
44 aria-label={caption ?? "Loading pull requests"}
45 className="motion-safe:animate-skeleton space-y-0.5"
46 >
47 {caption ? (
48 <p className="px-3 pb-1 text-xs font-medium text-muted-foreground/70">{caption}</p>
49 ) : null}
50 {Array.from({ length: rows }, (_, index) => (
51 <div
52 key={index}
53 className="grid grid-cols-[auto_minmax(0,1fr)_auto] items-center gap-3 rounded-lg px-3 py-2"
54 >
55 <GhostBar className="size-4 rounded-full" />
56 <div className="min-w-0 space-y-1.5">
57 <GhostBar className={cn("h-3.5", TITLE_WIDTHS[index % TITLE_WIDTHS.length])} />
58 <GhostBar className={META_WIDTHS[index % META_WIDTHS.length]} />
59 </div>
60 <div className="flex flex-col items-end gap-1.5">
61 <GhostBar className="w-12" />
62 <GhostBar className="w-16" />
63 </div>
64 </div>
65 ))}
66 </div>
67 );
69​
70/**
71 * The detail panel's current expanded shape. Keeping the chrome, summary facts, and description
72 * boundaries in the ghost prevents the loaded pull request from replacing one layout with
73 * another a moment later.
74 */
75export function PullRequestDetailGhost({ seed }: { seed?: PullRequestListEntry | null }) {
76 const statePresentation = seed
77 ? resolvePullRequestState({
78 state: seed.state,
79 isDraft: seed.isDraft,
80 })
81 : null;
82 const checksPresentation = seed?.checksState
83 ? pullRequestChecksStatePresentation(seed.checksState)
84 : null;
85​
86 return (
87 <div
88 role="status"
89 aria-label="Loading pull request"
90 className={cn(
91 "flex h-full min-h-0 flex-col overflow-hidden bg-background",
92 !seed && "motion-safe:animate-skeleton",
93 )}
94 >
95 <div className="shrink-0 border-b border-border/60">
96 <div className="flex h-7 items-center justify-between gap-3 px-4">
97 <div className="flex min-w-0 flex-1 items-center gap-1.5">
98 {seed && statePresentation ? (
99 <>
100 <span className="min-w-0 truncate text-xs font-medium text-muted-foreground">
101 {seed.repository}
102 </span>
103 <span
104 className={cn("shrink-0 text-xs font-medium", statePresentation.toneClassName)}
105 >
106 #{seed.number}
107 </span>
108 </>
109 ) : (
110 <>
111 <GhostBar className="w-24" />
112 <GhostBar className="w-9" />
113 </>
114 )}
115 </div>
116 <div className="flex shrink-0 items-center gap-1">
117 <GhostBar className="h-5 w-16 rounded-md" />
118 <GhostBar className="size-5 rounded-md" />
119 </div>
120 </div>
121​
122 <div className="px-4 pb-4 pt-1">
123 {seed ? (
124 <h1 className="truncate text-base font-semibold leading-snug">{seed.title}</h1>
125 ) : (
126 <GhostBar className="h-5 w-4/5 max-w-md" />
127 )}
128 <div className="mt-2 flex items-center gap-1.5">
129 {seed ? (
130 <>
131 <PullRequestActorLabel
132 actor={seed.author}
133 className="font-medium"
134 tooltip={false}
135 />
136 <span className="text-xs text-muted-foreground">
137 updated {formatRelativeTimeLabel(seed.updatedAt)}
138 </span>
139 </>
140 ) : (
141 <>
142 <GhostBar className="size-4 rounded-full" />
143 <GhostBar className="w-24" />
144 </>
145 )}
146 </div>
147 <div className="mt-4 flex min-w-0 items-center gap-2">
148 {seed ? (
149 <span className="flex min-w-0 flex-1 items-center gap-1.5 font-mono text-xs text-muted-foreground/70">
150 <code className="min-w-0 max-w-[40%] shrink-0 truncate">{seed.baseBranch}</code>
151 <ArrowLeftIcon
152 aria-label="receives changes from"
153 className="size-3.5 shrink-0 opacity-60"
154 />
155 <code className="min-w-0 flex-1 truncate">{seed.headBranch}</code>
156 </span>
157 ) : (
158 <>
159 <GhostBar className="h-6 w-24 rounded-md" />
160 <GhostBar className="size-3 rounded-full" />
161 <GhostBar className="h-6 w-32 rounded-md" />
162 </>
163 )}
164 <div className="ml-auto flex shrink-0 items-center gap-2">
165 <GhostBar className="w-10" />
166 {seed ? (
167 <PullRequestDiffStat
168 additions={seed.additions}
169 deletions={seed.deletions}
170 className="font-mono text-xs"
171 />
172 ) : (
173 <GhostBar className="w-20" />
174 )}
175 </div>
176 </div>
177 </div>
178​
179 <div className="flex min-h-10 items-center justify-between gap-3 border-t border-border/60 px-4 py-2">
180 <div className="flex items-center gap-1 p-0.5">
181 <GhostBar className="h-6 w-16 rounded-md" />
182 <GhostBar className="h-6 w-16 rounded-md" />
183 <GhostBar className="h-6 w-12 rounded-md" />
184 </div>
185 {checksPresentation ? (
186 <span
187 className={cn(
188 "inline-flex items-center gap-1.5 text-xs",
189 checksPresentation.toneClassName,
190 )}
191 >
192 <checksPresentation.Icon aria-hidden className="size-3.5" />
193 {checksPresentation.label}
194 </span>
195 ) : (
196 <GhostBar className="w-20" />
197 )}
198 </div>
199 </div>
200​
201 <div className="min-h-0 flex-1 overflow-hidden">
202 <section className="px-4 py-3">
203 <div className="grid min-h-8 grid-cols-[6rem_minmax(0,1fr)] items-center gap-2">
204 <div className="flex items-center gap-1.5">
205 <GhostBar className="size-3.5 rounded-full" />
206 <GhostBar className="w-14" />
207 </div>
208 <div className="flex items-center gap-1">
209 <GhostBar className="size-4 rounded-full" />
210 <GhostBar className="size-4 rounded-full" />
211 <GhostBar className="ml-1 size-5 rounded-md" />
212 </div>
213 </div>
214 <div className="grid min-h-8 grid-cols-[6rem_minmax(0,1fr)] items-center gap-2">
215 <div className="flex items-center gap-1.5">
216 <GhostBar className="size-3.5 rounded-full" />
217 <GhostBar className="w-10" />
218 </div>
219 <div className="flex items-center gap-1">
220 {seed ? (
221 seed.labels.slice(0, 3).map((label) => {
222 const color = pullRequestLabelColor(label.color);
223 return (
224 <span
225 key={label.name}
226 className="inline-flex h-5 max-w-32 items-center gap-1 truncate rounded-full border border-border/70 bg-muted/40 px-2 text-[10px] text-muted-foreground"
227 >
228 <span
229 aria-hidden
230 className="size-2 shrink-0 rounded-full bg-muted-foreground"
231 {...(color ? { style: { backgroundColor: color } } : {})}
232 />
233 <span className="truncate">{label.name}</span>
234 </span>
235 );
236 })
237 ) : (
238 <>
239 <GhostBar className="h-5 w-24 rounded-full" />
240 <GhostBar className="h-5 w-20 rounded-full" />
241 </>
242 )}
243 </div>
244 </div>
245 <div className="grid min-h-8 grid-cols-[6rem_minmax(0,1fr)] items-center gap-2">
246 <div className="flex items-center gap-1.5">
247 <GhostBar className="size-3.5 rounded-full" />
248 <GhostBar className="w-14" />
249 </div>
250 <GhostBar className="w-20" />
251 </div>
252 </section>
253​
254 <section className="border-t border-border/60">
255 <div className="flex min-h-11 items-center gap-1.5 px-4 py-3">
256 <GhostBar className="h-4 w-24" />
257 <GhostBar className="size-3.5 rounded-full" />
258 </div>
259 <div className="space-y-2 px-4 pb-4">
260 <GhostBar className="w-full" />
261 <GhostBar className="w-11/12" />
262 <GhostBar className="w-4/5" />
263 <GhostBar className="w-2/3" />
264 </div>
265 </section>
266 </div>
267 </div>
268 );
270​
271/** People-shaped: an avatar and a name, in the reviewer picker's own row height. */
272export function PullRequestPeopleGhost({ rows = 4 }: { rows?: number }) {
273 return (
274 <div
275 role="status"
276 aria-label="Loading people"
277 className="motion-safe:animate-skeleton space-y-1 p-1"
278 >
279 {Array.from({ length: rows }, (_, index) => (
280 <div key={index} className="flex h-7 items-center gap-2 rounded-md px-2">
281 <GhostBar className="size-4 rounded-full" />
282 <GhostBar className={META_WIDTHS[index % META_WIDTHS.length]} />
283 </div>
284 ))}
285 </div>
286 );
288​
289/** The timeline's own shape: dots on the rail, a line and a date to each. */
290export function PullRequestTimelineGhost({ rows = 6 }: { rows?: number }) {
291 return (
292 <div
293 role="status"
294 aria-label="Loading timeline"
295 className="motion-safe:animate-skeleton px-4 py-5"
296 >
297 <div className="relative ml-2 border-l border-border/70 pl-5">
298 {Array.from({ length: rows }, (_, index) => (
299 <div key={index} className="relative pb-5">
300 <GhostBar className="absolute -left-[1.55rem] top-1 size-2 rounded-full" />
301 <GhostBar className={cn("h-3.5", TITLE_WIDTHS[index % TITLE_WIDTHS.length])} />
302 <GhostBar className="mt-1.5 w-16" />
303 </div>
304 ))}
305 </div>
306 </div>
307 );
309​
310/** A compact placeholder for the conversation while the core detail is already readable. */
311export function PullRequestConversationGhost({ rows = 3 }: { rows?: number }) {
312 return (
313 <div
314 role="status"
315 aria-label="Loading pull request conversation"
316 className="motion-safe:animate-skeleton space-y-4 py-2"
317 >
318 {Array.from({ length: rows }, (_, index) => (
319 <div key={index} className="flex items-start gap-2">
320 <GhostBar className="size-5 shrink-0 rounded-full" />
321 <div className="flex-1 space-y-1.5">
322 <GhostBar className={META_WIDTHS[index % META_WIDTHS.length]} />
323 <GhostBar className="w-full" />
324 <GhostBar className="w-3/4" />
325 </div>
326 </div>
327 ))}
328 </div>
329 );