Open History to see the last commit
1import {
2 ArrowLeftIcon,
3 ChartNoAxesColumnIcon,
4 GitPullRequestIcon,
5 SettingsIcon,
6} from "lucide-react";
7import { memo, useCallback } from "react";
8import { Link, useLocation, useNavigate } from "@tanstack/react-router";
9
10import { useEnvironmentIdentificationMode } from "../../hooks/useSettings";
11import { cn } from "../../lib/utils";
12import { useEnvironments } from "../../state/environments";
13import {
14 resolveEnvironmentIdentificationPillLabel,
15 resolveSidebarStageBackdropVariant,
16 resolveSidebarStageFocusRingOffsetClass,
17 SidebarStageBackdrop,
18 useEnvironmentStageLabel,
19} from "../SidebarStageBackdrop";
20import { Badge } from "../ui/badge";
21import {
22 SidebarFooter,
23 SidebarHeader,
24 SidebarMenu,
25 SidebarMenuButton,
26 SidebarMenuItem,
27 SidebarTrigger,
28 useSidebar,
29} from "../ui/sidebar";
30import { Tooltip, TooltipPopup, TooltipTrigger } from "../ui/tooltip";
31import { SidebarProviderUpdatePill } from "./SidebarProviderUpdatePill";
32import { SidebarUpdateArchitectureWarning, SidebarUpdatePill } from "./SidebarUpdatePill";
33
34export const SidebarChromeHeader = memo(function SidebarChromeHeader({
35 isElectron,
36}: {
37 isElectron: boolean;
38}) {
39 const stageLabel = useEnvironmentStageLabel();
40 const environmentIdentificationMode = useEnvironmentIdentificationMode();
41 const backdropVariant = resolveSidebarStageBackdropVariant(
42 stageLabel,
43 environmentIdentificationMode === "artwork",
44 );
45 const pillLabel =
46 environmentIdentificationMode === "pill"
47 ? resolveEnvironmentIdentificationPillLabel(stageLabel)
48 : null;
49
50 return (
51 <SidebarHeader
52 className={cn(
53 "@container/sidebar-header relative h-[var(--workspace-topbar-height)] shrink-0 flex-row items-center px-3 py-0 md:px-0",
54 isElectron && "drag-region",
55 )}
56 >
57 {backdropVariant ? <SidebarStageBackdrop variant={backdropVariant} /> : null}
58 <SidebarTrigger
59 className={cn(
60 "relative z-10 md:hidden",
61 backdropVariant &&
62 "focus-visible:ring-white/90 [&_svg]:stroke-white/90! [&_svg]:opacity-100! [&_svg]:hover:stroke-white! [:hover,[data-pressed]]:bg-white/15",
63 backdropVariant && resolveSidebarStageFocusRingOffsetClass(backdropVariant),
64 )}
65 />
66 <SidebarBrand onBackdrop={backdropVariant !== null} />
67 {pillLabel ? (
68 <Badge
69 className="relative z-10 ml-1 rounded-full px-1.5 text-muted-foreground"
70 data-environment-identification="pill"
71 size="sm"
72 variant="secondary"
73 >
74 {pillLabel}
75 </Badge>
76 ) : null}
77 </SidebarHeader>
78 );
79});
80
81function SidebarBrand({ onBackdrop }: { onBackdrop: boolean }) {
82 return (
83 <Link
84 aria-label="Go to threads"
85 className={cn(
86 "relative z-10 ml-[var(--workspace-titlebar-content-left)] hidden h-7 w-fit min-w-0 shrink-0 items-center gap-1 overflow-hidden rounded-md outline-hidden ring-ring focus-visible:ring-2 md:flex",
87 onBackdrop ? "text-white" : "text-foreground",
88 )}
89 to="/"
90 >
91 <T3Wordmark />
92 <span
93 className={cn(
94 "-translate-y-px truncate text-sm font-medium tracking-tight",
95 onBackdrop ? "text-white/70" : "text-muted-foreground",
96 )}
97 >
98 Code
99 </span>
100 </Link>
101 );
102}
103
104function T3Wordmark() {
105 return (
106 <svg
107 aria-label="T3"
108 className="h-2.5 w-auto shrink-0"
109 viewBox="15.5309 37 94.3941 56.96"
110 xmlns="http://www.w3.org/2000/svg"
111 >
112 <path
113 d="M33.4509 93V47.56H15.5309V37H64.3309V47.56H46.4109V93H33.4509ZM86.7253 93.96C82.832 93.96 78.9653 93.4533 75.1253 92.44C71.2853 91.3733 68.032 89.88 65.3653 87.96L70.4053 78.04C72.5386 79.5867 75.0186 80.8133 77.8453 81.72C80.672 82.6267 83.5253 83.08 86.4053 83.08C89.6586 83.08 92.2186 82.44 94.0853 81.16C95.952 79.88 96.8853 78.12 96.8853 75.88C96.8853 73.7467 96.0586 72.0667 94.4053 70.84C92.752 69.6133 90.0853 69 86.4053 69H80.4853V60.44L96.0853 42.76L97.5253 47.4H68.1653V37H107.365V45.4L91.8453 63.08L85.2853 59.32H89.0453C95.9253 59.32 101.125 60.8667 104.645 63.96C108.165 67.0533 109.925 71.0267 109.925 75.88C109.925 79.0267 109.099 81.9867 107.445 84.76C105.792 87.48 103.259 89.6933 99.8453 91.4C96.432 93.1067 92.0586 93.96 86.7253 93.96Z"
114 fill="currentColor"
115 />
116 </svg>
117 );
118}
119
120export const SidebarChromeFooter = memo(function SidebarChromeFooter() {
121 const navigate = useNavigate();
122 const { isMobile, setOpenMobile } = useSidebar();
123 const currentFooterPage = useLocation({
124 select: (location) =>
125 location.pathname === "/usage"
126 ? "usage"
127 : location.pathname === "/pull-requests"
128 ? "pull-requests"
129 : null,
130 });
131 const { environments } = useEnvironments();
132 // The page reads every connected server, so one of them offering pull requests is enough for
133 // the link to lead somewhere.
134 const pullRequestsSupported = environments.some(
135 (environment) => environment.serverConfig?.environment.capabilities.pullRequests === true,
136 );
137 const closeMobileSidebar = useCallback(() => {
138 if (isMobile) {
139 setOpenMobile(false);
140 }
141 }, [isMobile, setOpenMobile]);
142 const handlePullRequestsClick = useCallback(() => {
143 closeMobileSidebar();
144 void navigate({ to: "/pull-requests", search: { involvement: "all", state: "open" } });
145 }, [closeMobileSidebar, navigate]);
146 const handleSettingsClick = useCallback(() => {
147 closeMobileSidebar();
148 void navigate({ to: "/settings" });
149 }, [closeMobileSidebar, navigate]);
150
151 const handleUsageClick = useCallback(() => {
152 if (isMobile) {
153 setOpenMobile(false);
154 }
155 void navigate({ to: "/usage" });
156 }, [isMobile, navigate, setOpenMobile]);
157
158 const handleBackClick = useCallback(() => {
159 closeMobileSidebar();
160 void navigate({ to: "/" });
161 }, [closeMobileSidebar, navigate]);
162
163 return (
164 <SidebarFooter className="p-[var(--sidebar-content-inset)]">
165 <SidebarProviderUpdatePill />
166 <SidebarUpdateArchitectureWarning />
167 <SidebarMenu className="flex-row items-center">
168 {currentFooterPage ? (
169 <SidebarMenuItem className="min-w-0 flex-1">
170 <SidebarMenuButton onClick={handleBackClick}>
171 <ArrowLeftIcon />
172 <span>Back</span>
173 </SidebarMenuButton>
174 </SidebarMenuItem>
175 ) : (
176 <>
177 <SidebarMenuItem className="shrink-0">
178 <Tooltip>
179 <TooltipTrigger
180 render={
181 <SidebarMenuButton
182 aria-label="Settings"
183 onClick={handleSettingsClick}
184 size="icon"
185 >
186 <SettingsIcon />
187 </SidebarMenuButton>
188 }
189 />
190 <TooltipPopup side="top">Settings</TooltipPopup>
191 </Tooltip>
192 </SidebarMenuItem>
193 {pullRequestsSupported ? (
194 <SidebarMenuItem className="shrink-0">
195 <Tooltip>
196 <TooltipTrigger
197 render={
198 <SidebarMenuButton
199 aria-label="Pull Requests"
200 onClick={handlePullRequestsClick}
201 size="icon"
202 >
203 <GitPullRequestIcon />
204 </SidebarMenuButton>
205 }
206 />
207 <TooltipPopup side="top">Pull Requests</TooltipPopup>
208 </Tooltip>
209 </SidebarMenuItem>
210 ) : null}
211 <SidebarMenuItem className="shrink-0">
212 <Tooltip>
213 <TooltipTrigger
214 render={
215 <SidebarMenuButton aria-label="Usage" onClick={handleUsageClick} size="icon">
216 <ChartNoAxesColumnIcon />
217 </SidebarMenuButton>
218 }
219 />
220 <TooltipPopup side="top">Usage</TooltipPopup>
221 </Tooltip>
222 </SidebarMenuItem>
223 </>
224 )}
225 <SidebarUpdatePill />
226 </SidebarMenu>
227 </SidebarFooter>
228 );
229});