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

ThreadContextChip.tsx

50 lines1.9 KB

1import { scopeProjectRef } from "@t3tools/client-runtime/environment";
2import type { ThreadContextRecord } from "@t3tools/contracts";
3import { Link } from "@tanstack/react-router";
4import { MessagesSquareIcon } from "lucide-react";
5​
6import { useProject, useThreadShell } from "~/state/entities";
7import { ContextChip, ContextChipLabel } from "./ContextChip";
8import { ProjectFavicon } from "./ProjectFavicon";
9import { Tooltip, TooltipPopup, TooltipTrigger } from "./ui/tooltip";
10​
11export function ThreadContextChip(props: {
12 record: Pick<ThreadContextRecord, "environmentId" | "threadId" | "title">;
13 copyMarkdown?: string;
14 unreadable?: boolean;
15}) {
16 const { environmentId, threadId } = props.record;
17 const shell = useThreadShell({ environmentId, threadId });
18 const project = useProject(shell ? scopeProjectRef(environmentId, shell.projectId) : null);
19 const title = shell?.title?.trim() || props.record.title;
20 return (
21 <Tooltip>
22 <TooltipTrigger
23 render={
24 <ContextChip
25 kind="thread"
26 {...(props.unreadable ? { state: "invalid" as const } : {})}
27 render={<Link to="/$environmentId/$threadId" params={{ environmentId, threadId }} />}
28 aria-label={`Thread, ${title}`}
29 data-markdown-copy={props.copyMarkdown}
30 className="no-underline"
31 >
32 {project ? (
33 <ProjectFavicon project={project} className="size-[1.17em] self-center" />
34 ) : (
35 <MessagesSquareIcon />
36 )}
37 <ContextChipLabel>{title}</ContextChipLabel>
38 </ContextChip>
39 }
40 />
41 <TooltipPopup side="top">
42 {props.unreadable
43 ? "On another machine, so this machine's agent can't read it. Remove it or switch back to send."
44 : shell
45 ? "Open thread"
46 : "Thread no longer available"}
47 </TooltipPopup>
48 </Tooltip>
49 );