Skip to content
TypeScript

fix(web): thread links render as chips, and thread chips show the project icon (#22621)

oliver15dc7b0130ca
diff --git a/apps/web/src/components/ThreadContextChip.tsx b/apps/web/src/components/ThreadContextChip.tsx
index f120cbde298..5f1a4202f1d 100644
--- a/apps/web/src/components/ThreadContextChip.tsx
+++ b/apps/web/src/components/ThreadContextChip.tsx
@@ -1,9 +1,11 @@
+import { scopeProjectRef } from "@t3tools/client-runtime/environment";
import type { ThreadContextRecord } from "@t3tools/contracts";
import { Link } from "@tanstack/react-router";
import { MessagesSquareIcon } from "lucide-react";
-import { useThreadShell } from "~/state/entities";
+import { useProject, useThreadShell } from "~/state/entities";
import { ContextChip, ContextChipLabel } from "./ContextChip";
+import { ProjectFavicon } from "./ProjectFavicon";
import { Tooltip, TooltipPopup, TooltipTrigger } from "./ui/tooltip";
export function ThreadContextChip(props: {
@@ -13,6 +15,7 @@ export function ThreadContextChip(props: {
}) {
const { environmentId, threadId } = props.record;
const shell = useThreadShell({ environmentId, threadId });
+ const project = useProject(shell ? scopeProjectRef(environmentId, shell.projectId) : null);
const title = shell?.title?.trim() || props.record.title;
return (
<Tooltip>
@@ -26,7 +29,11 @@ export function ThreadContextChip(props: {
data-markdown-copy={props.copyMarkdown}
className="no-underline"
>
- <MessagesSquareIcon />
+ {project ? (
+ <ProjectFavicon project={project} className="size-[1.17em] self-center" />
+ ) : (
+ <MessagesSquareIcon />
+ )}
<ContextChipLabel>{title}</ContextChipLabel>
</ContextChip>
}
diff --git a/apps/web/src/components/chat/MarkdownThreadLink.tsx b/apps/web/src/components/chat/MarkdownThreadLink.tsx
index 4996be3884a..8b32a541223 100644
--- a/apps/web/src/components/chat/MarkdownThreadLink.tsx
+++ b/apps/web/src/components/chat/MarkdownThreadLink.tsx
@@ -1,15 +1,13 @@
-import { scopeProjectRef, scopeThreadRef } from "@t3tools/client-runtime/environment";
+import { scopeThreadRef } from "@t3tools/client-runtime/environment";
import type { EnvironmentId, ThreadId } from "@t3tools/contracts";
import {
formatThreadLink,
percentDecodedThreadLinkId,
resolveThreadLinkRef,
} from "@t3tools/shared/threadLinks";
-import { Link } from "@tanstack/react-router";
-import { MessageSquareTextIcon } from "lucide-react";
-import { useProject, useThreadRefs, useThreadShell } from "../../state/entities";
-import { ProjectFavicon } from "../ProjectFavicon";
+import { useThreadRefs, useThreadShell } from "../../state/entities";
+import { ThreadContextChip } from "../ThreadContextChip";
export function MarkdownThreadLink(props: {
readonly environmentId: EnvironmentId;
@@ -31,28 +29,11 @@ export function MarkdownThreadLink(props: {
const thread = local ?? remote;
const environmentId = thread?.environmentId ?? props.environmentId;
const threadId = thread?.id ?? props.threadId;
- const project = useProject(
- thread === null ? null : scopeProjectRef(environmentId, thread.projectId),
- );
const title = thread?.title.trim() || props.label;
return (
- <Link
- to="/$environmentId/$threadId"
- params={{ environmentId, threadId }}
- title={thread === null ? "Thread no longer available" : project?.title}
- data-markdown-copy={formatThreadLink(threadId, title)}
- >
- <span
- className="ms-[0.25em] me-[0.2em] inline-flex size-[14px] [vertical-align:-0.125em]"
- aria-hidden
- >
- {project === null ? (
- <MessageSquareTextIcon className="block size-full shrink-0" />
- ) : (
- <ProjectFavicon project={project} className="size-full" />
- )}
- </span>
- {title}
- </Link>
+ <ThreadContextChip
+ record={{ environmentId, threadId, title: props.label }}
+ copyMarkdown={formatThreadLink(threadId, title)}
+ />
);
}
diff --git a/apps/web/src/index.css b/apps/web/src/index.css
index 346d4d85cde..354a096d6b2 100644
--- a/apps/web/src/index.css
+++ b/apps/web/src/index.css
@@ -1955,13 +1955,23 @@ code {
text-decoration: none;
}
-/* File links are Chips and own their color and focus ring. */
-.chat-markdown a:not(.chat-markdown-file-link) {
+/* File links and context chips own their color and focus ring. */
+.chat-markdown a:not(.chat-markdown-file-link, :has([data-slot="context-chip-label"])) {
color: var(--info-foreground);
}
-.chat-markdown a:not(.chat-markdown-file-link, [data-markdown-image-link]):hover,
-.chat-markdown a:not(.chat-markdown-file-link, [data-markdown-image-link]):focus-visible {
+.chat-markdown
+ a:not(
+ .chat-markdown-file-link,
+ :has([data-slot="context-chip-label"]),
+ [data-markdown-image-link]
+ ):hover,
+.chat-markdown
+ a:not(
+ .chat-markdown-file-link,
+ :has([data-slot="context-chip-label"]),
+ [data-markdown-image-link]
+ ):focus-visible {
background-image: radial-gradient(circle, currentcolor 0.75px, transparent 1px);
background-position: left bottom;
background-repeat: repeat-x;