| 1 | import type { EnvironmentId } from "@t3tools/contracts"; |
| 2 | import { createContext, useContext } from "react"; |
| 3 | |
| 4 | import { cn } from "~/lib/utils"; |
| 5 | |
| 6 | import { PullRequestMarkdown } from "../PullRequestMarkdown"; |
| 7 | |
| 8 | /** Where the guide's prose renders from: the pull request's environment and checkout. */ |
| 9 | export const GuideProseContext = createContext<{ |
| 10 | readonly environmentId: EnvironmentId; |
| 11 | readonly cwd: string; |
| 12 | } | null>(null); |
| 13 | |
| 14 | /** |
| 15 | * The guide's sentences, rendered as the pull request's own description is: inline code, and |
| 16 | * `#123` linked to that pull request or issue, opening in the pull request panel like every other |
| 17 | * pull request link in the app. Plain text inside a control, such as a question that opens a |
| 18 | * thread, since a link cannot nest in a button. |
| 19 | */ |
| 20 | export function GuideProse({ |
| 21 | text, |
| 22 | plain = false, |
| 23 | className, |
| 24 | }: { |
| 25 | text: string; |
| 26 | plain?: boolean; |
| 27 | className?: string; |
| 28 | }) { |
| 29 | const context = useContext(GuideProseContext); |
| 30 | if (plain || context === null) return text; |
| 31 | return ( |
| 32 | <PullRequestMarkdown |
| 33 | text={text} |
| 34 | cwd={context.cwd} |
| 35 | environmentId={context.environmentId} |
| 36 | // The element around it sets size and colour; the description's spacing is for a page. |
| 37 | className={cn("space-y-0 [&_.chat-markdown]:text-inherit", className)} |
| 38 | /> |
| 39 | ); |
| 40 | } |