|
| 1 | +import { scopeProjectRef, scopeThreadRef } from "@t3tools/client-runtime/environment"; |
| 2 | +import type { EnvironmentId, ThreadId } from "@t3tools/contracts"; |
| 3 | +import { formatThreadLink } from "@t3tools/shared/threadLinks"; |
| 4 | +import { Link } from "@tanstack/react-router"; |
| 5 | +import { MessageSquareTextIcon } from "lucide-react"; |
| 6 | + |
| 7 | +import { useProject, useThreadShell } from "../../state/entities"; |
| 8 | +import { ProjectFavicon } from "../ProjectFavicon"; |
| 9 | + |
| 10 | +/** |
| 11 | + * A `t3-thread://` link in chat. It shows the thread's current title, so a rename |
| 12 | + * reaches every message that links to it, and leads with the thread's project icon |
| 13 | + * the way a web link leads with its favicon. `label` is what the message wrote, |
| 14 | + * shown only when this client cannot see the thread. Opens the thread in the app. |
| 15 | + */ |
| 16 | +export function MarkdownThreadLink(props: { |
| 17 | + readonly environmentId: EnvironmentId; |
| 18 | + readonly threadId: ThreadId; |
| 19 | + readonly label: string; |
| 20 | +}) { |
| 21 | + const thread = useThreadShell(scopeThreadRef(props.environmentId, props.threadId)); |
| 22 | + const project = useProject( |
| 23 | + thread === null ? null : scopeProjectRef(props.environmentId, thread.projectId), |
| 24 | + ); |
| 25 | + const title = thread?.title.trim() || props.label; |
| 26 | + return ( |
| 27 | + <Link |
| 28 | + to="/$environmentId/$threadId" |
| 29 | + params={{ environmentId: props.environmentId, threadId: props.threadId }} |
| 30 | + title={project?.title} |
| 31 | + data-markdown-copy={formatThreadLink(props.threadId, title)} |
| 32 | + > |
| 33 | + <span |
| 34 | + className="ms-[0.25em] me-[0.2em] inline-flex size-[14px] [vertical-align:-0.125em]" |
| 35 | + aria-hidden |
| 36 | + > |
| 37 | + {project === null ? ( |
| 38 | + <MessageSquareTextIcon className="block size-full shrink-0" /> |
| 39 | + ) : ( |
| 40 | + <ProjectFavicon project={project} className="size-full" /> |
| 41 | + )} |
| 42 | + </span> |
| 43 | + {title} |
| 44 | + </Link> |
| 45 | + ); |
| 46 | +} |
0 commit comments