Open History to see the last commit
1import { ChartNoAxesColumnIcon, GitPullRequestIcon, SettingsIcon } from "lucide-react";
2import { memo, useCallback } from "react";
3import { Link, useNavigate } from "@tanstack/react-router";
4
5import { useEnvironmentIdentificationMode } from "../../hooks/useSettings";
6import { cn } from "../../lib/utils";
7import { usePrimaryEnvironment } from "../../state/environments";
8import {
9 resolveEnvironmentIdentificationPillLabel,
10 resolveSidebarStageBackdropVariant,
11 SidebarStageBackdrop,
12 useEnvironmentStageLabel,
13} from "../SidebarStageBackdrop";
14import { Badge } from "../ui/badge";
15import {
16 SidebarFooter,
17 SidebarHeader,
18 SidebarMenu,
19 SidebarMenuButton,
20 SidebarMenuItem,
21 SidebarTrigger,
22 useSidebar,
23} from "../ui/sidebar";
24import { SidebarProviderUpdatePill } from "./SidebarProviderUpdatePill";
25import { SidebarUpdatePill } from "./SidebarUpdatePill";
26
27export const SidebarChromeHeader = memo(function SidebarChromeHeader({
28 isElectron,
29}: {
30 isElectron: boolean;
31}) {
32 const stageLabel = useEnvironmentStageLabel();
33 const environmentIdentificationMode = useEnvironmentIdentificationMode();
34 const backdropVariant = resolveSidebarStageBackdropVariant(
35 stageLabel,
36 environmentIdentificationMode === "artwork",
37 );
38 const pillLabel =
39 environmentIdentificationMode === "pill"
40 ? resolveEnvironmentIdentificationPillLabel(stageLabel)
41 : null;
42
43 return (
44 <SidebarHeader
45 className={cn(
46 "@container/sidebar-header relative h-[var(--workspace-topbar-height)] shrink-0 flex-row items-center px-3 py-0 md:px-0",
47 isElectron && "drag-region",
48 )}
49 >
50 {backdropVariant ? <SidebarStageBackdrop variant={backdropVariant} /> : null}
51 <SidebarTrigger
52 className={cn(
53 "relative z-10 md:hidden",
54 backdropVariant &&
55 "[:hover,[data-pressed]]:bg-white/15 focus-visible:ring-white/90 focus-visible:ring-offset-blue-700 [&_svg]:stroke-white/90! [&_svg]:opacity-100! [&_svg]:hover:stroke-white!",
56 )}
57 />
58 <SidebarBrand onBackdrop={backdropVariant !== null} />
59 {pillLabel ? (
60 <Badge
61 className="relative z-10 ml-1 rounded-full px-1.5 text-muted-foreground"
62 data-environment-identification="pill"
63 size="sm"
64 variant="secondary"
65 >
66 {pillLabel}
67 </Badge>
68 ) : null}
69 </SidebarHeader>
70 );
71});
72
73function SidebarBrand({ onBackdrop }: { onBackdrop: boolean }) {
74 return (
75 <Link
76 aria-label="Go to threads"
77 className={cn(
78 "sidebar-brand relative z-10 ml-[var(--workspace-titlebar-content-left)] 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",
79 onBackdrop ? "text-white" : "text-foreground",
80 )}
81 to="/"
82 >
83 <T3Wordmark />
84 <span
85 className={cn(
86 "truncate text-sm font-medium tracking-tight",
87 onBackdrop ? "text-white/70" : "text-muted-foreground",
88 )}
89 >
90 Code
91 </span>
92 </Link>
93 );
94}
95
96function T3Wordmark() {
97 return (
98 <svg
99 aria-label="T3"
100 className="h-2.5 w-auto shrink-0"
101 viewBox="15.5309 37 94.3941 56.96"
102 xmlns="http://www.w3.org/2000/svg"
103 >
104 <path
105 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"
106 fill="currentColor"
107 />
108 </svg>
109 );
110}
111
112export const SidebarChromeFooter = memo(function SidebarChromeFooter() {
113 const navigate = useNavigate();
114 const { isMobile, setOpenMobile } = useSidebar();
115 const primaryEnvironment = usePrimaryEnvironment();
116 const pullRequestsSupported =
117 primaryEnvironment?.serverConfig?.environment.capabilities.pullRequests === true;
118 const closeMobileSidebar = useCallback(() => {
119 if (isMobile) {
120 setOpenMobile(false);
121 }
122 }, [isMobile, setOpenMobile]);
123 const handlePullRequestsClick = useCallback(() => {
124 closeMobileSidebar();
125 void navigate({ to: "/pull-requests", search: { involvement: "all", state: "open" } });
126 }, [closeMobileSidebar, navigate]);
127 const handleSettingsClick = useCallback(() => {
128 closeMobileSidebar();
129 void navigate({ to: "/settings" });
130 }, [closeMobileSidebar, navigate]);
131
132 const handleUsageClick = useCallback(() => {
133 if (isMobile) {
134 setOpenMobile(false);
135 }
136 void navigate({ to: "/usage" });
137 }, [isMobile, navigate, setOpenMobile]);
138
139 return (
140 <SidebarFooter className="p-[var(--sidebar-content-inset)]">
141 <SidebarProviderUpdatePill />
142 <SidebarUpdatePill />
143 <SidebarMenu>
144 {pullRequestsSupported ? (
145 <SidebarMenuItem>
146 <SidebarMenuButton onClick={handlePullRequestsClick}>
147 <GitPullRequestIcon />
148 <span>Pull Requests</span>
149 </SidebarMenuButton>
150 </SidebarMenuItem>
151 ) : null}
152 <SidebarMenuItem>
153 <SidebarMenuButton onClick={handleUsageClick}>
154 <ChartNoAxesColumnIcon />
155 <span>Usage</span>
156 </SidebarMenuButton>
157 </SidebarMenuItem>
158 <SidebarMenuItem>
159 <SidebarMenuButton onClick={handleSettingsClick}>
160 <SettingsIcon />
161 <span>Settings</span>
162 </SidebarMenuButton>
163 </SidebarMenuItem>
164 </SidebarMenu>
165 </SidebarFooter>
166 );
167});