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

PullRequestMarkdown.tsx

58 lines2.4 KB

1import { ExternalLinkIcon, PaperclipIcon, PlayIcon } from "lucide-react";
2​
3import { cn } from "~/lib/utils";
4​
5import ChatMarkdown from "../ChatMarkdown";
6import { splitPullRequestBody } from "./pullRequestMarkdown.logic";
7​
8/**
9 * A pull request body, rendered with the app's markdown renderer plus a card for each upload
10 * embedded in it, which that renderer drops on the floor.
11 *
12 * The card links out instead of playing in place, because nothing here can play. A
13 * `github.com/user-attachments/assets/…` link is a 302 to a signed S3 URL that serves the file
14 * as uploaded — `video/quicktime` for anything recorded on a Mac, which no Chromium decodes —
15 * and the desktop window's content policy declares no `media-src`, so media falls back to
16 * `default-src 'self'` and every remote source is refused before a byte is fetched. A player
17 * here can only be the box that never fills in; a card that opens the host is a real answer.
18 */
19export function PullRequestMarkdown({
20 text,
21 cwd,
22 className,
23}: {
24 text: string;
25 cwd: string;
26 className?: string;
27}) {
28 const segments = splitPullRequestBody(text);
29 return (
30 <div className={cn("space-y-3", className)}>
31 {segments.map((segment) => {
32 if (segment.kind === "markdown") {
33 return <ChatMarkdown key={segment.id} text={segment.text} cwd={cwd} />;
34 }
35 const isVideo = segment.media === "video";
36 const Icon = isVideo ? PlayIcon : PaperclipIcon;
37 return (
38 // A plain anchor rather than the page's openExternal button: the desktop window
39 // turns a blocked _blank into openExternal itself, and in a browser tab — where
40 // there is no shell to call — this is the only one of the two that goes anywhere.
41 <a
42 key={segment.id}
43 href={segment.url}
44 rel="noreferrer noopener"
45 target="_blank"
46 className="flex items-center gap-2 rounded-lg border border-border/60 bg-muted/30 px-3 py-2 text-sm hover:bg-muted/60"
47 >
48 <Icon aria-hidden className="size-3.5 shrink-0 text-muted-foreground" />
49 <span className="min-w-0 flex-1 truncate">
50 {isVideo ? "Play video on GitHub" : "Open attachment on GitHub"}
51 </span>
52 <ExternalLinkIcon aria-hidden className="size-3 shrink-0 text-muted-foreground" />
53 </a>
54 );
55 })}
56 </div>
57 );