Open History to see the last commit
1import { type EnvironmentId } from "@t3tools/contracts";
2import { memo } from "react";
3import { readLocalApi } from "~/localApi";
4
5import { cn } from "~/lib/utils";
6import { ProjectFavicon } from "../ProjectFavicon";
7import { Tooltip, TooltipPopup, TooltipTrigger } from "../ui/tooltip";
8
9interface ChatHeaderProps {
10 activeThreadEnvironmentId: EnvironmentId;
11 activeThreadTitle: string;
12 activeProjectName: string | undefined;
13 activeProjectCwd: string | null;
14 activeProjectFaviconPath: string | null;
15 activeProjectIcon: import("@t3tools/contracts").ProjectIconOverride | null;
16 rightPanelOpen: boolean;
17 onNewThreadInProject: () => void;
18 onOpenProjectSettings?: (() => void) | undefined;
19}
20
21export const ChatHeader = memo(function ChatHeader({
22 activeThreadEnvironmentId,
23 activeThreadTitle,
24 activeProjectName,
25 activeProjectCwd,
26 activeProjectFaviconPath,
27 activeProjectIcon,
28 rightPanelOpen,
29 onNewThreadInProject,
30 onOpenProjectSettings,
31}: ChatHeaderProps) {
32 return (
33 <div
34 onContextMenu={
35 onOpenProjectSettings === undefined
36 ? undefined
37 : (event) => {
38 event.preventDefault();
39 const api = readLocalApi();
40 if (!api) return;
41 void api.contextMenu
42 .show([{ id: "project-settings", label: "Project settings", icon: "settings" }], {
43 x: event.clientX,
44 y: event.clientY,
45 })
46 .then((action) => {
47 if (action === "project-settings") onOpenProjectSettings();
48 });
49 }
50 }
51 className={cn(
52 "flex min-w-0 flex-1 items-center gap-2 sm:gap-3",
53 rightPanelOpen ? "pr-10" : "pr-24",
54 )}
55 >
56 <div className="flex min-w-0 flex-1 items-center gap-2 overflow-hidden sm:gap-3">
57 {/* The project always leads the header: knowing which project a
58 thread lives in is priority zero, and the thread title alone
59 doesn't answer it. */}
60 {activeProjectName ? (
61 <span className="inline-flex shrink-0 items-center gap-2">
62 <Tooltip>
63 <TooltipTrigger
64 render={
65 <button
66 type="button"
67 aria-label={`New thread in ${activeProjectName}`}
68 onClick={onNewThreadInProject}
69 className="inline-flex min-w-0 cursor-pointer items-center gap-1.5 rounded-sm text-muted-foreground transition-colors hover:text-foreground focus-visible:outline-hidden focus-visible:ring-2 focus-visible:ring-ring"
70 />
71 }
72 >
73 <ProjectFavicon
74 environmentId={activeThreadEnvironmentId}
75 cwd={activeProjectCwd ?? ""}
76 faviconPath={activeProjectFaviconPath}
77 projectIcon={activeProjectIcon}
78 projectName={activeProjectName}
79 className="size-3.5"
80 />
81 <span className="max-w-40 truncate text-sm font-medium">{activeProjectName}</span>
82 </TooltipTrigger>
83 <TooltipPopup side="top">New thread in {activeProjectName}</TooltipPopup>
84 </Tooltip>
85 <span aria-hidden className="text-muted-foreground/40">
86 /
87 </span>
88 </span>
89 ) : null}
90 <Tooltip>
91 <TooltipTrigger
92 render={
93 <h2
94 aria-label={activeThreadTitle}
95 className="min-w-0 flex-1 truncate text-sm font-medium text-foreground"
96 >
97 {activeThreadTitle}
98 </h2>
99 }
100 />
101 <TooltipPopup side="top">{activeThreadTitle}</TooltipPopup>
102 </Tooltip>
103 </div>
104 </div>
105 );
106});