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

ChatHeader.tsx

91 lines3.2 KB

1import type { EnvironmentProject } from "@t3tools/client-runtime/state/shell";
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 activeThreadTitle: string;
11 activeProject: EnvironmentProject | null;
12 rightPanelOpen: boolean;
13 onNewThreadInProject: () => void;
14 onOpenProjectSettings?: (() => void) | undefined;
16​
17export const ChatHeader = memo(function ChatHeader({
18 activeThreadTitle,
19 activeProject,
20 rightPanelOpen,
21 onNewThreadInProject,
22 onOpenProjectSettings,
23}: ChatHeaderProps) {
24 return (
25 <div
26 onContextMenu={
27 onOpenProjectSettings === undefined
28 ? undefined
29 : (event) => {
30 event.preventDefault();
31 const api = readLocalApi();
32 if (!api) return;
33 void api.contextMenu
34 .show([{ id: "project-settings", label: "Project settings", icon: "settings" }], {
35 x: event.clientX,
36 y: event.clientY,
37 })
38 .then((action) => {
39 if (action === "project-settings") onOpenProjectSettings();
40 });
41 }
42 }
43 className={cn(
44 "flex min-w-0 flex-1 items-center gap-2 sm:gap-3",
45 rightPanelOpen ? "pr-10" : "pr-24",
46 )}
47 >
48 <div className="flex min-w-0 flex-1 items-center gap-2 overflow-hidden sm:gap-3">
49 {/* The project always leads the header: knowing which project a
50 thread lives in is priority zero, and the thread title alone
51 doesn't answer it. */}
52 {activeProject ? (
53 <span className="inline-flex shrink-0 items-center gap-2">
54 <Tooltip>
55 <TooltipTrigger
56 render={
57 <button
58 type="button"
59 aria-label={`New thread in ${activeProject.title}`}
60 onClick={onNewThreadInProject}
61 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"
62 />
63 }
64 >
65 <ProjectFavicon project={activeProject} className="size-3.5" />
66 <span className="max-w-40 truncate text-sm font-medium">{activeProject.title}</span>
67 </TooltipTrigger>
68 <TooltipPopup side="top">New thread in {activeProject.title}</TooltipPopup>
69 </Tooltip>
70 <span aria-hidden className="text-muted-foreground/40">
71 /
72 </span>
73 </span>
74 ) : null}
75 <Tooltip>
76 <TooltipTrigger
77 render={
78 <h2
79 aria-label={activeThreadTitle}
80 className="min-w-0 flex-1 truncate text-sm font-medium text-foreground"
81 >
82 {activeThreadTitle}
83 </h2>
84 }
85 />
86 <TooltipPopup side="top">{activeThreadTitle}</TooltipPopup>
87 </Tooltip>
88 </div>
89 </div>
90 );
91});