Skip to content

g1t/apps/web/app/components/shell.tsx

1,886 lines77,936 bytesCodeBlame
1import { Activity, BarChart3, Bell, BookMarked, BookOpen, Bot, Box, Brain, Check, ChevronDown, ChevronLeft, ChevronRight, ChevronsUpDown, CircleDot, GripVertical, CircleUserRound, Code2, Compass, CreditCard, Fingerprint, GanttChart, Gauge, GitBranch, GitPullRequest, Globe, History, House, Inbox, KanbanSquare, KeyRound, LayoutDashboard, LayoutGrid, LifeBuoy, ListTree, Lock, LogIn, LogOut, Mail, Menu, Network, Package, PlayCircle, Plug, Plus, Rocket, Search, ServerCog, Settings, ShieldCheck, Sparkles, Ticket, TrendingUp, Users, UsersRound, Webhook, X } from "lucide-react";
2import { type ReactNode, useEffect, useMemo, useRef, useState } from "react";
3import { Link, NavLink, useFetcher, useLocation, useNavigation, useRouteLoaderData, useSubmit } from "react-router";
4
5import { type Abilities, type InboxCounts, type Membership, type Spike, type User, mayCreateTeams } from "@g1t/contracts";
6
7import { CommandPalette, type PaletteCommand, PaletteKey, usePaletteShortcut } from "./command-palette";
8import { AgentButton, InboxBell } from "./inbox";
9import { PinButton } from "./pin-button";
10import { Tooltip, TooltipContent, TooltipTrigger } from "./ui/tooltip";
11import { Hint } from "./ui/hint";
12import { Sheet, SheetContent, SheetTitle, SheetTrigger } from "./ui/sheet";
13import { StatusDot, useSiteStatus } from "./footer";
14import { Logo, Mark } from "./logo";
15import { Avatar, SoonPill } from "./ui";
16import { Skeleton } from "./ui/skeleton";
17import {
18 DropdownMenu,
19 DropdownMenuContent,
20 DropdownMenuGroup,
21 DropdownMenuItem,
22 DropdownMenuLabel,
23 DropdownMenuSeparator,
24 DropdownMenuTrigger,
25} from "./ui/dropdown-menu";
26import { type RoadmapItem, roadmapIn, roadmapItem } from "../lib/roadmap";
27import { SETTINGS_PAGES, sidebarCurrent } from "../lib/workspace-nav";
28import { SETTINGS_CAPABILITY, type ViewerAccess, seesSettings } from "../lib/access";
29import { VISITOR_LINKS, projectPages } from "../lib/chrome";
30import { ACCOUNT_SETTINGS, type AccountSettingsPage, FIRST_SETTINGS_PAGE, accountSettingsPage } from "../lib/account-settings";
31import { GithubMark } from "./github";
32import { withNext } from "../lib/next";
33import { useSignUpCopy } from "../lib/registration";
34import { STATUS_URL, statusTitle } from "../lib/status";
35import { type ShortcutProject, movedPin, recentWith } from "../lib/pins";
36import type { AccountMenuData } from "../routes/settings-menu-json";
37
38/**
39 * What the sidebar needs, worked out by the root loader. For a visitor who
40 * is not signed in there is no workspace, no projects and no usage: only
41 * the project being looked at, if they can see it.
42 */
43export type ShellData = {
44 /** The workspace the sidebar is about: the one being looked at, or their first. */
45 workspace: Membership | null;
46 /** All its projects, by name, for the palette: `name` is the slug in their address. */
47 repos: ShortcutProject[];
48 /** The person's pinned projects in it, in their order (lib/pins.ts). */
49 pinned?: ShortcutProject[];
50 /** What they opened there last, latest first, leaving out the pinned. */
51 recent?: ShortcutProject[];
52 /** Repositories shared with them in workspaces they do not belong to. */
53 shared?: { namespace: string; name: string; isPrivate: boolean }[];
54 /** The project being looked at, if any, whoever owns it. */
55 repo: {
56 namespace: string;
57 name: string;
58 member: boolean;
59 issues: number;
60 pulls: number;
61 } | null;
62 /** Where the workspace stands against its usage limit, if billing is on. */
63 limit: {
64 exposureMicros: number;
65 ceilingMicros: number | null;
66 state: "ok" | "warning" | "stopped";
67 comped: boolean;
68 } | null;
69 /** Whether g1t charges nothing for now, while it is being built out. */
70 free?: boolean;
71 /** What its agents have cost since the start of the month. */
72 /** This month's usage: charged, or at cost while g1t is free. */
73 monthUsageMicros: number | null;
74 /** Whether new compute is paused (a spend spike or a hold), and whether the viewer can answer it. */
75 compute?: { paused: string | null; spike: Spike | null; owner: boolean } | null;
76 /** What is unread in their inbox, for the bell. Absent for a visitor. */
77 inbox?: InboxCounts | null;
78};
79
80function SidebarLink({
81 to,
82 icon,
83 end,
84 count,
85 also,
86 drill,
87 current: lit,
88 children,
89}: {
90 to: string;
91 icon: ReactNode;
92 end?: boolean;
93 count?: number;
94 /** Other path prefixes under which this link is the current one. */
95 also?: string | string[];
96 /** It opens a list of its own: a chevron says so, always or on hover. */
97 drill?: boolean | "hover";
98 /** Whether it is the current row, when the list works that out itself. */
99 current?: boolean;
100 children: ReactNode;
101}) {
102 const { pathname } = useLocation();
103 return (
104 <NavLink
105 to={to}
106 end={end}
107 prefetch="intent"
108 className={({ isActive, isPending }) => {
109 const current =
110 lit ??
111 (isActive || [also ?? []].flat().some((prefix) => pathname === prefix || pathname.startsWith(prefix + "/")));
112 return `group flex h-8 items-center gap-2.5 rounded-md px-2 text-[0.8125rem] transition-colors ${
113 current
114 ? "bg-raised font-medium text-fg"
115 : isPending
116 ? "bg-raised/60 text-fg"
117 : "text-muted hover:bg-raised/60 hover:text-fg"
118 }`;
119 }}
120 >
121 <span className="shrink-0 text-faint group-hover:text-muted">{icon}</span>
122 <span className="min-w-0 grow truncate">{children}</span>
123 {count != null && count > 0 && (
124 <span className="rounded bg-line px-1.5 text-[0.6875rem] tabular-nums text-muted">
125 {count}
126 </span>
127 )}
128 {drill && (
129 <ChevronRight
130 size={14}
131 aria-hidden="true"
132 className={`-mr-0.5 shrink-0 text-faint transition-opacity ${drill === "hover" ? "opacity-0 group-hover:opacity-100 group-focus-visible:opacity-100" : ""}`}
133 />
134 )}
135 </NavLink>
136 );
137}
138
139/**
140 * Something a project will have, shown where it will live so people can
141 * see where g1t is going. Not a link: nothing is behind it yet.
142 */
143function SidebarSoon({ icon, children, about }: { icon: ReactNode; children: ReactNode; about: string }) {
144 return (
145 <Hint label={about} side="right">
146 <div aria-disabled="true" className="flex h-8 cursor-default items-center gap-2.5 rounded-md px-2 text-[0.8125rem] text-faint">
147 <span className="shrink-0 opacity-70">{icon}</span>
148 <span className="grow truncate">{children}</span>
149 <span className="sr-only">{about}</span>
150 <SoonPill />
151 </div>
152 </Hint>
153 );
154}
155
156/**
157 * A page that is coming, as a link to its roadmap page: faint, with Soon,
158 * and marked current on any of its section's Soon pages.
159 */
160function SidebarSoonLink({
161 to,
162 also,
163 icon,
164 about,
165 current: lit,
166 children,
167}: {
168 to: string;
169 also?: string[];
170 icon: ReactNode;
171 about: string;
172 /** Whether it is the current row, when the list works that out itself. */
173 current?: boolean;
174 children: ReactNode;
175}) {
176 const { pathname } = useLocation();
177 return (
178 // The hint wraps a plain box: Radix's asChild merges className as a
179 // string, which would break NavLink's className function.
180 <Hint label={about} side="right">
181 <div>
182 <NavLink
183 to={to}
184 prefetch="intent"
185 className={({ isActive }) => {
186 const current = lit ?? (isActive || (also ?? []).some((prefix) => pathname === prefix || pathname.startsWith(prefix + "/")));
187 return `group flex h-8 items-center gap-2.5 rounded-md px-2 text-[0.8125rem] transition-colors ${
188 current ? "bg-raised font-medium text-fg" : "text-faint hover:bg-raised/60 hover:text-muted"
189 }`;
190 }}
191 >
192 <span className="shrink-0 opacity-80">{icon}</span>
193 <span className="min-w-0 grow truncate">{children}</span>
194 <SoonPill />
195 </NavLink>
196 </div>
197 </Hint>
198 );
199}
200
201/** Icons for what spans projects. */
202const WORKSPACE_ICONS: Record<string, ReactNode> = {
203 board: <KanbanSquare size={15} />,
204 roadmap: <GanttChart size={15} />,
205 teams: <UsersRound size={15} />,
206 packages: <Package size={15} />,
207 fleet: <Bot size={15} />,
208};
209
210/** The Soon pages of a section, as paths, so its link is current on them. */
211function soonPaths(base: string, section: RoadmapItem["section"]): string[] {
212 return roadmapIn(section).map((item) => `${base}/soon/${item.key}`);
213}
214
215function SidebarGroup({
216 title,
217 action,
218 className = "",
219 children,
220}: {
221 title: string;
222 action?: ReactNode;
223 className?: string;
224 children: ReactNode;
225}) {
226 return (
227 <section className={className}>
228 <div className="mb-1 flex h-6 items-center justify-between px-2">
229 <h2 className="text-xs font-medium text-faint">{title}</h2>
230 {action}
231 </div>
232 <div className="space-y-px">{children}</div>
233 </section>
234 );
235}
236
237/** What a workspace is called where people read it: its display name, else its slug. */
238function displayName(membership: Membership): string {
239 return membership.name?.trim() || membership.slug;
240}
241
242function WorkspaceSwitcher({ user, shell }: { user: User; shell: ShellData }) {
243 const workspace = shell.workspace;
244 const current = workspace?.slug;
245 const label = workspace ? displayName(workspace) : "Choose a workspace";
246 return (
247 <DropdownMenu>
248 {/* The name goes to the workspace; only the arrows switch it. The
249 name gets all the room there is, and the whole of it on hover. */}
250 <Hint label={workspace ? `${label} · g1t.sh/${workspace.slug}` : undefined}>
251 <Link
252 to={current ? `/${current}` : "/workspaces/new"}
253 prefetch="intent"
254 className="flex h-9 min-w-0 grow items-center gap-2 rounded-md px-2 transition-colors hover:bg-raised"
255 >
256 {workspace ? (
257 <Avatar name={workspace.slug} image={workspace.avatar} size={20} square />
258 ) : (
259 <span className="size-5 shrink-0 rounded-md border border-dashed border-line-strong" />
260 )}
261 <span className="min-w-0 truncate text-[0.8125rem] font-medium">{label}</span>
262 </Link>
263 </Hint>
264 <DropdownMenuTrigger
265 aria-label="Switch workspace"
266 className="flex h-9 w-7 shrink-0 items-center justify-center rounded-md text-faint outline-none transition-colors hover:bg-raised hover:text-fg focus-visible:ring-2 focus-visible:ring-accent data-[state=open]:bg-raised data-[state=open]:text-fg"
267 >
268 <ChevronsUpDown size={14} />
269 </DropdownMenuTrigger>
270 <DropdownMenuContent align="start" className="w-64">
271 {workspace && (
272 <>
273 {/* The workspace's own page: its projects, packages and people. */}
274 <DropdownMenuItem asChild>
275 <Link to={`/${workspace.slug}`}>
276 <LayoutGrid />
277 Workspace overview
278 </Link>
279 </DropdownMenuItem>
280 <DropdownMenuItem asChild>
281 <Link to={`/${workspace.slug}/-/projects`}>
282 <Box />
283 All projects
284 </Link>
285 </DropdownMenuItem>
286 <DropdownMenuSeparator />
287 </>
288 )}
289 <DropdownMenuLabel>Workspaces</DropdownMenuLabel>
290 {(user.workspaces ?? []).map((membership) => (
291 <Hint key={membership.slug} label={displayName(membership)} side="right">
292 <DropdownMenuItem asChild>
293 <Link to={`/${membership.slug}`}>
294 <Avatar name={membership.slug} image={membership.avatar} size={24} square />
295 <span className="flex min-w-0 grow flex-col leading-tight">
296 <span className="truncate">{displayName(membership)}</span>
297 <span className="truncate font-mono text-[0.6875rem] text-faint">{membership.slug}</span>
298 </span>
299 <span className="shrink-0 text-[0.6875rem] text-faint capitalize">{membership.role}</span>
300 {membership.slug === current ? (
301 <Check className="shrink-0 text-accent" />
302 ) : (
303 <span className="size-4 shrink-0" aria-hidden="true" />
304 )}
305 </Link>
306 </DropdownMenuItem>
307 </Hint>
308 ))}
309 <DropdownMenuSeparator />
310 <DropdownMenuItem asChild>
311 <Link to="/workspaces/new">
312 <Plus />
313 New workspace
314 </Link>
315 </DropdownMenuItem>
316 </DropdownMenuContent>
317 </DropdownMenu>
318 );
319}
320
321/**
322 * The fine print, as one quiet row at the foot of the account menu and the
323 * visitor's panel: each link a full-height target, left-aligned. In the
324 * menu each is a menu item, so the arrow keys reach it.
325 */
326const LEGAL_LINKS: [string, string][] = [
327 ["Policies", "/policies"],
328 ["Privacy", "/policies/privacy"],
329 ["Security", "/security"],
330];
331const LEGAL_LINK = "flex h-7 items-center rounded px-1.5 text-xs text-faint outline-none transition-colors";
332
333function MenuLegalRow() {
334 return (
335 <div role="group" aria-label="Legal" className="flex items-center gap-0.5 px-0.5 pt-0.5">
336 {LEGAL_LINKS.map(([label, to], index) => (
337 <span key={to} className="flex items-center gap-0.5">
338 {index > 0 && (
339 <span aria-hidden="true" className="text-[0.625rem] text-line-strong">
340 ·
341 </span>
342 )}
343 <DropdownMenuItem asChild className={`${LEGAL_LINK} py-0 data-highlighted:bg-line data-highlighted:text-fg`}>
344 <Link to={to}>{label}</Link>
345 </DropdownMenuItem>
346 </span>
347 ))}
348 </div>
349 );
350}
351
352/** Status's row: the live dot and two or three words, fetched when the menu opens. */
353function StatusSummary({ open }: { open: boolean }) {
354 const status = useSiteStatus(open);
355 const words = statusTitle(status);
356 return (
357 <span className="ml-auto flex min-w-0 items-center gap-1.5 pl-2 text-xs text-faint">
358 {/* The words say it; the dot's own words for screen readers would repeat them. */}
359 <span aria-hidden="true" className="flex">
360 <StatusDot state={status?.overall.state ?? null} />
361 </span>
362 {words ? <span className="truncate">{words}</span> : <Skeleton className="h-3 w-20" />}
363 </span>
364 );
365}
366
367/** A menu row: an icon, words, and whatever sits at its end. */
368const MENU_ROW = "h-9 gap-2.5 px-2.5 text-[0.8125rem]";
369
370function AccountMenu({ user }: { user: User }) {
371 const submit = useSubmit();
372 const [open, setOpen] = useState(false);
373 // Name, primary address and invites left: asked for once, as soon as the
374 // pointer or focus reaches the button, so they are there when it opens.
375 const details = useFetcher<AccountMenuData | null>({ key: "account-menu" });
376 const prefetch = () => {
377 if (details.state === "idle" && details.data === undefined) details.load("/settings/menu.json");
378 };
379 useEffect(() => {
380 if (open) prefetch();
381 // eslint-disable-next-line react-hooks/exhaustive-deps
382 }, [open]);
383 const me = details.data ?? null;
384 // Still on its way: shapes where the words will be, the same size.
385 const loading = details.data === undefined && details.state !== "idle";
386 const profile = `/u/${user.username}`;
387 return (
388 <DropdownMenu open={open} onOpenChange={setOpen}>
389 <DropdownMenuTrigger
390 aria-label={`Account menu for ${user.username}`}
391 onPointerEnter={prefetch}
392 onFocus={prefetch}
393 className="flex h-10 w-full items-center gap-2.5 rounded-md px-2 text-left outline-none transition-colors hover:bg-raised focus-visible:ring-2 focus-visible:ring-accent/60 data-[state=open]:bg-raised"
394 >
395 <Avatar name={user.username} image={user.avatar} size={22} />
396 <span className="min-w-0 grow truncate text-[0.8125rem] font-medium">{user.username}</span>
397 <ChevronsUpDown size={14} className="shrink-0 text-faint" />
398 </DropdownMenuTrigger>
399 <DropdownMenuContent align="start" side="top" collisionPadding={8} className="w-[17.5rem] p-1.5">
400 {/* Who is signed in, and a way to their profile. */}
401 <DropdownMenuItem asChild className="gap-3 px-2 py-2">
402 <Link to={profile} aria-label={`${me?.name ?? user.username} (@${user.username}), your profile`}>
403 <Avatar name={user.username} image={user.avatar} size={36} />
404 <span className="flex min-w-0 grow flex-col leading-tight" aria-busy={loading}>
405 {loading ? (
406 <Skeleton className="my-[0.1875rem] h-3.5 w-28" />
407 ) : (
408 <span className="truncate text-sm font-medium text-fg">{me?.name ?? user.username}</span>
409 )}
410 <span className="truncate font-mono text-xs text-muted">@{user.username}</span>
411 {loading ? (
412 <Skeleton className="mt-1 h-3 w-40" />
413 ) : (
414 me?.email && <span className="mt-0.5 truncate text-xs text-faint">{me.email}</span>
415 )}
416 </span>
417 </Link>
418 </DropdownMenuItem>
419 <DropdownMenuSeparator className="my-1.5" />
420 <DropdownMenuGroup>
421 <DropdownMenuItem asChild className={MENU_ROW}>
422 <Link to={profile}>
423 <CircleUserRound />
424 Your profile
425 </Link>
426 </DropdownMenuItem>
427 <DropdownMenuItem asChild className={MENU_ROW}>
428 <Link to={FIRST_SETTINGS_PAGE}>
429 <Settings />
430 Your settings
431 </Link>
432 </DropdownMenuItem>
433 <DropdownMenuItem asChild className={MENU_ROW}>
434 <Link to="/settings/invites">
435 <Ticket />
436 Invites
437 {loading && <Skeleton className="ml-auto h-4 w-12 rounded-full" />}
438 {me?.invites_left != null && (
439 <span className="ml-auto rounded-full bg-line px-1.5 text-[0.6875rem] tabular-nums text-muted">
440 {me.invites_left} left
441 </span>
442 )}
443 </Link>
444 </DropdownMenuItem>
445 </DropdownMenuGroup>
446 <DropdownMenuSeparator className="my-1.5" />
447 <DropdownMenuGroup>
448 <DropdownMenuItem asChild className={MENU_ROW}>
449 <a href="https://docs.g1t.sh/">
450 <BookOpen />
451 Documentation
452 </a>
453 </DropdownMenuItem>
454 <DropdownMenuItem asChild className={MENU_ROW}>
455 <Link to="/support">
456 <LifeBuoy />
457 Support
458 </Link>
459 </DropdownMenuItem>
460 <DropdownMenuItem asChild className={MENU_ROW}>
461 <a href={STATUS_URL}>
462 <Activity />
463 Status
464 <StatusSummary open={open} />
465 </a>
466 </DropdownMenuItem>
467 </DropdownMenuGroup>
468 <DropdownMenuSeparator className="my-1.5" />
469 {/* Submitted from here: the menu closes on select, and a button
470 that has left the page cannot submit a form. */}
471 <DropdownMenuItem className={MENU_ROW} onSelect={() => submit(null, { method: "post", action: "/logout" })}>
472 <LogOut />
473 Sign out
474 </DropdownMenuItem>
475 <DropdownMenuSeparator className="my-1.5" />
476 <MenuLegalRow />
477 </DropdownMenuContent>
478 </DropdownMenu>
479 );
480}
481
482/**
483 * A workspace's settings pages, which the sidebar drills into: how it is
484 * set up and connected (guardrails, secrets, runners, integrations,
485 * webhooks), what it pays, its repositories, tokens and record. The main
486 * list keeps the places work happens and who belongs; every member can
487 * still open these.
488 */
489const SETTINGS_PAGE =
490 new RegExp(`^/([^/]+)/-/(${SETTINGS_PAGES.join("|")})(/|$)`);
491/** A project's settings pages, which the project's menu drills into. */
492const REPO_SETTINGS_PAGE = /^\/([^/]+)\/([^/-][^/]*)\/settings(\/|$)/;
493
494/**
495 * The sidebar's lists are a stack, the way a phone pushes a screen: one
496 * drilled into slides in from the right over the full width, while the one
497 * it covers drifts a quarter of the way left and fades, both on one long
498 * ease-out, the fade quicker than the move so the two never blur together.
499 * Going back reverses it.
500 */
501const LAYER =
502 "absolute inset-0 [transition:translate_380ms_cubic-bezier(0.32,0.72,0,1),opacity_220ms_ease-out] will-change-[translate,opacity] motion-reduce:transition-none";
503/** One list, filling its layer. */
504const PANEL = "h-full overflow-y-auto px-2 pb-4";
505
506/** One list in the stack: what it is, and its rows. */
507type Level = { key: string; node: ReactNode };
508
509/** True once the page has hydrated, so what the server drew never animates in. */
510function useHydrated(): boolean {
511 const [hydrated, setHydrated] = useState(false);
512 useEffect(() => setHydrated(true), []);
513 return hydrated;
514}
515
516/**
517 * Drilling in and out of the sidebar's lists. `trail` is the way from the
518 * main list to the one shown, worked out from the address, so a link
519 * straight to a settings page opens the sidebar already drilled in, and
520 * leaving it comes back out. Lists deeper than the one shown stay in
521 * place, off to the right, so going back slides them away rather than
522 * dropping them. Moving to a list at the same depth (a workspace's settings
523 * to a project) fades the new one in where it is.
524 */
525function Drill({ trail }: { trail: Level[] }) {
526 const depth = trail.length - 1;
527 const hydrated = useHydrated();
528 const stack = useRef<Level[]>(trail);
529 const before = stack.current;
530 const within = trail.every((level, index) => before[index]?.key === level.key);
531 stack.current = within ? [...trail, ...before.slice(trail.length)] : trail;
532 const levels = stack.current;
533 // What was showing last time, to tell drilling in from moving across.
534 const shown = useRef({ depth, keys: levels.map((level) => level.key) });
535 useEffect(() => {
536 shown.current = { depth, keys: levels.map((level) => level.key) };
537 });
538 return (
539 <div className="relative min-h-0 grow overflow-hidden">
540 {levels.map((level, index) => {
541 const current = index === depth;
542 const place =
543 index < depth
544 ? "pointer-events-none -translate-x-1/4 opacity-0"
545 : current
546 ? "translate-x-0 opacity-100"
547 : "pointer-events-none translate-x-full opacity-0";
548 // A list that was not there before arrives: from the right when
549 // drilling in, in place when moving across.
550 const arriving = hydrated && current && !shown.current.keys.includes(level.key);
551 const enter = arriving
552 ? depth > shown.current.depth
553 ? "starting:translate-x-full starting:opacity-0"
554 : "starting:opacity-0"
555 : "";
556 return (
557 <div key={level.key} className={`${LAYER} ${place} ${enter}`} inert={!current} aria-hidden={!current || undefined}>
558 {level.node}
559 </div>
560 );
561 })}
562 </div>
563 );
564}
565
566/**
567 * The row at the top of a list drilled into: the list's name, which goes
568 * back out, and what it belongs to, faint at the end.
569 */
570function BackRow({ to, label, context }: { to: string; label: ReactNode; context?: ReactNode }) {
571 return (
572 <Link
573 to={to}
574 prefetch="intent"
575 className="group mt-3 flex h-8 items-center gap-1.5 rounded-md pr-2 pl-1 text-[0.8125rem] font-medium text-fg transition-colors hover:bg-raised/60"
576 >
577 <ChevronLeft size={16} className="shrink-0 text-faint transition-transform group-hover:-translate-x-0.5 group-hover:text-muted" />
578 <span className="min-w-0 shrink-0 truncate">{label}</span>
579 {context && (
580 <span className="ml-auto min-w-0 truncate pl-2 font-mono text-[0.6875rem] font-normal text-faint">{context}</span>
581 )}
582 </Link>
583 );
584}
585
586/** A thin rule between groups of a list. */
587function Rule() {
588 return <div role="separator" className="mx-2 my-2.5 h-px bg-line" />;
589}
590
591/** A quiet heading inside a group: Pinned, Recent. */
592function SidebarSubhead({ children }: { children: ReactNode }) {
593 return <h3 className="px-2 pt-1.5 pb-0.5 text-[0.6875rem] font-medium tracking-wide text-faint">{children}</h3>;
594}
595
596/**
597 * The workspace's projects as the sidebar keeps them, however many there
598 * are: the person's pins in their order, what they opened last, and the
599 * way to all of them. Pins move by dragging, or with Alt and the arrow
600 * keys; the projects service keeps the order.
601 */
602function SidebarProjects({ slug, shell, current }: { slug: string; shell: ShellData; current: boolean }) {
603 const reorder = useFetcher({ key: `pins:${slug}` });
604 const saved = shell.pinned ?? [];
605 // While a new order is on its way, it shows as made.
606 const asked = reorder.formData?.get("intent") === "reorder" ? reorder.formData.getAll("slug").map(String) : null;
607 const pinned = asked
608 ? asked.map((name) => saved.find((project) => project.name === name)).filter((project): project is ShortcutProject => project != null)
609 : saved;
610 const active = shell.repo ? { namespace: shell.repo.namespace, name: shell.repo.name, isPrivate: false } : null;
611 const recent = recentWith(shell.recent ?? [], pinned, active, slug);
612 const [dragging, setDragging] = useState<number | null>(null);
613 const move = (from: number, by: number) => {
614 const next = movedPin(pinned, from, by);
615 if (!next) return;
616 const form = new FormData();
617 form.set("intent", "reorder");
618 for (const project of next) form.append("slug", project.name);
619 reorder.submit(form, { method: "post", action: `/${slug}/-/pins` });
620 };
621 // Each row pins or unpins in place: the pin shows on hover or focus, and
622 // stays shown on a pinned row's hover so it reads as "unpin".
623 const row = (project: ShortcutProject, isPinned: boolean) => (
624 <div className="group/row relative">
625 <SidebarLink to={`/${project.namespace}/${project.name}`} icon={project.isPrivate ? <Lock size={15} /> : <Box size={15} />} drill="hover">
626 <span className="block truncate pr-6">{project.title ?? project.name}</span>
627 </SidebarLink>
628 <PinButton
629 workspace={slug}
630 slug={project.name}
631 name={project.title ?? project.name}
632 pinned={isPinned}
633 small
634 className="absolute top-1/2 right-6 -translate-y-1/2 opacity-0 transition-opacity group-hover/row:opacity-100 focus-within:opacity-100 [@media(hover:none)]:opacity-100"
635 />
636 </div>
637 );
638 return (
639 <SidebarGroup
640 title="Projects"
641 action={
642 <Link to={`/new?workspace=${slug}`} aria-label="New project" className="rounded p-0.5 text-faint hover:bg-raised hover:text-fg">
643 <Plus size={13} />
644 </Link>
645 }
646 >
647 {/* Only there once something is pinned: each row below has its own pin. */}
648 {pinned.length > 0 && (
649 <>
650 <SidebarSubhead>Pinned</SidebarSubhead>
651 <ul aria-label="Pinned projects" className="space-y-px">
652 {pinned.map((project, index) => (
653 <li
654 key={project.name}
655 draggable={pinned.length > 1}
656 onDragStart={(event) => {
657 setDragging(index);
658 event.dataTransfer.effectAllowed = "move";
659 }}
660 onDragOver={(event) => {
661 if (dragging != null) event.preventDefault();
662 }}
663 onDrop={(event) => {
664 event.preventDefault();
665 if (dragging != null && dragging !== index) move(dragging, index - dragging);
666 setDragging(null);
667 }}
668 onDragEnd={() => setDragging(null)}
669 onKeyDown={(event) => {
670 if (!event.altKey || (event.key !== "ArrowUp" && event.key !== "ArrowDown")) return;
671 event.preventDefault();
672 move(index, event.key === "ArrowUp" ? -1 : 1);
673 }}
674 className={`group/pin relative ${dragging === index ? "opacity-50" : ""}`}
675 >
676 {row(project, true)}
677 {pinned.length > 1 && (
678 <Hint label="Drag, or Alt and an arrow key, to reorder" side="right">
679 <span className="absolute top-1/2 -left-1.5 -translate-y-1/2 cursor-grab text-faint opacity-0 transition-opacity group-hover/pin:opacity-100">
680 <GripVertical size={12} aria-hidden="true" />
681 </span>
682 </Hint>
683 )}
684 </li>
685 ))}
686 </ul>
687 </>
688 )}
689 {recent.length > 0 && (
690 <>
691 <SidebarSubhead>Recent</SidebarSubhead>
692 {recent.map((project) => (
693 <div key={`${project.namespace}/${project.name}`}>{row(project, false)}</div>
694 ))}
695 </>
696 )}
697 <div className="pt-1">
698 <SidebarLink to={`/${slug}/-/projects`} icon={<LayoutGrid size={15} />} count={shell.repos.length} current={current}>
699 All projects
700 </SidebarLink>
701 </div>
702 </SidebarGroup>
703 );
704}
705
706/**
707 * The main list, in two parts a rule apart. Above it, what is yours
708 * whichever workspace you are in: Mission control, your inbox, and what
709 * others have shared with you. Below it, under the workspace's name, the
710 * workspace: its overview, its projects, what it builds and runs with
711 * across them, then its people, usage, support and settings. One row is
712 * lit wherever you are (lib/workspace-nav.ts).
713 */
714function MainMenu({ user, shell }: { user: User | null; shell: ShellData }) {
715 const ws = shell.workspace;
716 const { pathname } = useLocation();
717 const going = useNavigation().location?.pathname;
718 // The row lights as the link is followed, not once the page arrives.
719 const here = sidebarCurrent(going ?? pathname, ws?.slug ?? null);
720 // A visitor browses: no workspace, no projects of their own.
721 if (!user) {
722 return (
723 <nav aria-label="g1t" className={PANEL}>
724 <div className="mt-3 space-y-px">
725 {VISITOR_LINKS.map((link) => (
726 <SidebarLink key={link.to} to={link.to} icon={link.to === "/search" ? <Search size={15} /> : <Compass size={15} />}>
727 {link.label}
728 </SidebarLink>
729 ))}
730 </div>
731 </nav>
732 );
733 }
734 const shared = shell.shared ?? [];
735 return (
736 <nav aria-label="g1t" className={PANEL}>
737 {/* Yours, in every workspace. Explore, all of g1t, is in the top bar. */}
738 <div className="mt-3 space-y-px">
739 <SidebarLink to="/" end icon={<House size={15} />} current={here === "mission"}>
740 Mission control
741 </SidebarLink>
742 <SidebarLink to="/inbox" icon={<Inbox size={15} />} count={shell.inbox?.unread ?? undefined} current={here === "inbox"}>
743 Inbox
744 </SidebarLink>
745 </div>
746 {shared.length > 0 && (
747 <SidebarGroup title="Shared with you" className="mt-3">
748 {shared.map((repo) => (
749 <SidebarLink
750 key={`${repo.namespace}/${repo.name}`}
751 to={`/${repo.namespace}/${repo.name}`}
752 icon={repo.isPrivate ? <Lock size={15} /> : <Box size={15} />}
753 drill="hover"
754 >
755 <span className="font-mono text-faint">{repo.namespace}/</span>
756 {repo.name}
757 </SidebarLink>
758 ))}
759 </SidebarGroup>
760 )}
761
762 <Rule />
763 {ws ? (
764 <>
765 {/* The workspace the switcher names: its own page first. */}
766 <SidebarGroup title={displayName(ws)}>
767 <SidebarLink to={`/${ws.slug}`} end icon={<LayoutDashboard size={15} />} current={here === "overview"}>
768 Overview
769 </SidebarLink>
770 </SidebarGroup>
771 <div className="mt-3">
772 <SidebarProjects slug={ws.slug} shell={shell} current={here === "projects"} />
773 </div>
774
775 <Rule />
776 <div className="space-y-px">
777 <SidebarLink to={`/${ws.slug}/-/agents`} icon={<Bot size={15} />} current={here === "agents"}>
778 Agent fleet
779 </SidebarLink>
780 <SidebarLink to={`/${ws.slug}/-/context`} icon={<Network size={15} />} current={here === "context"}>
781 Context
782 </SidebarLink>
783 <SidebarLink to={`/${ws.slug}/-/memory`} icon={<Brain size={15} />} current={here === "memory"}>
784 Memory
785 </SidebarLink>
786 <SidebarLink to={`/${ws.slug}/-/security`} icon={<ShieldCheck size={15} />} current={here === "security"}>
787 Security
788 </SidebarLink>
789 <SidebarLink to={`/${ws.slug}/-/packages`} icon={<Package size={15} />} current={here === "packages"}>
790 Packages
791 </SidebarLink>
792 {INSIGHTS && (
793 <SidebarSoonLink
794 to={`/${ws.slug}/-/insights`}
795 icon={<TrendingUp size={15} />}
796 about={INSIGHTS.summary}
797 current={here === "insights"}
798 >
799 {INSIGHTS.title}
800 </SidebarSoonLink>
801 )}
802 {roadmapIn("Workspace").filter((item) => item.key !== "insights").map((item) => (
803 <SidebarSoonLink
804 key={item.key}
805 to={`/${ws.slug}/-/soon/${item.key}`}
806 icon={WORKSPACE_ICONS[item.key] ?? <Sparkles size={15} />}
807 about={item.summary}
808 >
809 {item.title === "Board" ? "Boards" : item.title}
810 </SidebarSoonLink>
811 ))}
812 </div>
813
814 <Rule />
815 <div className="space-y-px">
816 {/* Who belongs, for every member to see; owners invite and manage there. */}
817 <SidebarLink to={`/${ws.slug}/-/people`} icon={<Users size={15} />} current={here === "people"}>
818 People
819 </SidebarLink>
820 <SidebarLink to={`/${ws.slug}/-/teams`} icon={WORKSPACE_ICONS.teams} current={here === "teams"}>
821 Teams
822 </SidebarLink>
823 <SidebarLink to={`/${ws.slug}/-/usage`} icon={<BarChart3 size={15} />} current={here === "usage"}>
824 Usage
825 </SidebarLink>
826 <SidebarLink to="/support" icon={<LifeBuoy size={15} />} current={here === "support"}>
827 Support
828 </SidebarLink>
829 {/* How it is set up and connected, what it pays and its record: a list of their own. */}
830 <SidebarLink
831 to={ws.role === "owner" ? `/${ws.slug}/-/settings` : `/${ws.slug}/-/repositories`}
832 icon={<Settings size={15} />}
833 drill
834 current={here === "settings"}
835 >
836 Settings
837 </SidebarLink>
838 </div>
839 </>
840 ) : (
841 <SidebarGroup title="Projects">
842 <p className="px-2 py-1 text-xs text-faint">None yet.</p>
843 </SidebarGroup>
844 )}
845 </nav>
846 );
847}
848
849/** Insights, coming: the workspace's own page says what it will be. */
850const INSIGHTS = roadmapItem("insights");
851
852/** A workspace's settings, drilled into from Settings in the main list. */
853function SettingsMenu({ slug, owner }: { slug: string; owner: boolean }) {
854 return (
855 <nav aria-label="Workspace settings" className={PANEL}>
856 <BackRow to={`/${slug}`} label="Settings" context={slug} />
857 <div className="mt-2 space-y-px">
858 {owner && (
859 <SidebarLink to={`/${slug}/-/settings`} icon={<Settings size={15} />}>
860 General
861 </SidebarLink>
862 )}
863 <SidebarLink to={`/${slug}/-/repositories`} icon={<BookMarked size={15} />}>
864 Repositories
865 </SidebarLink>
866 <SidebarLink to={`/${slug}/-/tokens`} icon={<KeyRound size={15} />}>
867 Access tokens
868 </SidebarLink>
869 </div>
870 <SidebarGroup title="Agents and runs" className="mt-3">
871 <SidebarLink to={`/${slug}/-/guardrails`} icon={<Gauge size={15} />}>
872 Guardrails
873 </SidebarLink>
874 <SidebarLink to={`/${slug}/-/secrets`} icon={<Lock size={15} />}>
875 Secrets and variables
876 </SidebarLink>
877 {owner && (
878 <SidebarLink to={`/${slug}/-/runners`} icon={<ServerCog size={15} />}>
879 Runners
880 </SidebarLink>
881 )}
882 </SidebarGroup>
883 <SidebarGroup title="Connections" className="mt-3">
884 <SidebarLink to={`/${slug}/-/integrations`} icon={<Plug size={15} />}>
885 Integrations
886 </SidebarLink>
887 <SidebarLink to={`/${slug}/-/webhooks`} icon={<Webhook size={15} />}>
888 Webhooks
889 </SidebarLink>
890 </SidebarGroup>
891 <Rule />
892 <div className="space-y-px">
893 <SidebarLink to={`/${slug}/-/billing`} icon={<CreditCard size={15} />}>
894 Billing and plans
895 </SidebarLink>
896 <SidebarLink to={`/${slug}/-/audit`} icon={<History size={15} />}>
897 Audit log
898 </SidebarLink>
899 </div>
900 </nav>
901 );
902}
903
904/**
905 * What the repository menu needs. Known from the address before the page's
906 * data arrives, so the menu is right from the first frame; the counts fill
907 * in once it does.
908 */
909type MenuRepo = {
910 namespace: string;
911 name: string;
912 member: boolean;
913 /** Whether they see its settings; from the repository's page once it loads. */
914 settings?: boolean;
915 /** What they may do there, once the repository's page loads. */
916 can?: Abilities;
917 issues?: number;
918 pulls?: number;
919};
920
921function sameRepo(a: { namespace: string; name: string } | null, b: { namespace: string; name: string } | null) {
922 return (
923 a != null &&
924 b != null &&
925 a.namespace.toLowerCase() === b.namespace.toLowerCase() &&
926 a.name.toLowerCase() === b.name.toLowerCase()
927 );
928}
929
930/**
931 * A project's own list, drilled into while you are in it: everything about
932 * the project, running and its code, and nothing else, with the way back
933 * out to all of them.
934 */
935function RepoMenu({
936 repo,
937 isPrivate,
938 back,
939}: {
940 repo: MenuRepo;
941 isPrivate: boolean;
942 /** Where the way back leads: the workspace's projects, mission control, or Explore. */
943 back: { to: string; label: string };
944}) {
945 const base = `/${repo.namespace}/${repo.name}`;
946 // What a member sees, and what everyone who can see the project does.
947 const shows = new Set(projectPages(repo.member, repo.can));
948 return (
949 <nav aria-label={`${repo.namespace}/${repo.name}`} className={PANEL}>
950 <BackRow to={back.to} label={back.label} />
951 <Hint label="Overview" side="right">
952 <div>
953 <NavLink
954 to={base}
955 end
956 prefetch="intent"
957 className={({ isActive }) =>
958 `mt-2 flex items-center gap-2 rounded-md px-2 py-1.5 transition-colors ${isActive ? "bg-raised" : "hover:bg-raised/60"}`
959 }
960 >
961 <span className="flex size-6 shrink-0 items-center justify-center rounded-md bg-raised text-muted ring-1 ring-line">
962 {isPrivate ? <Lock size={13} /> : <Box size={13} />}
963 </span>
964 <span className="min-w-0 truncate font-mono text-[0.8125rem]">
965 <span className="text-faint">{repo.namespace}/</span>
966 <span className="font-semibold text-fg">{repo.name}</span>
967 </span>
968 </NavLink>
969 </div>
970 </Hint>
971 {/* A project's pages, in the order people use them. A page with more
972 than one view shows them as tabs across its top. */}
973 <Rule />
974 <div className="space-y-px">
975 <SidebarLink to={`${base}/code`} also={[`${base}/tree`, `${base}/blob`, `${base}/commits`, `${base}/commit`, `${base}/branches`, `${base}/tags`, `${base}/compare`, ...soonPaths(base, "Code")]} icon={<Code2 size={15} />}>
976 Code
977 </SidebarLink>
978 <SidebarLink to={`${base}/issues`} also={[`${base}/plans`, `${base}/milestones`, `${base}/labels`, ...soonPaths(base, "Issues")]} icon={<CircleDot size={15} />} count={repo.issues}>
979 Issues
980 </SidebarLink>
981 <SidebarLink to={`${base}/pulls`} also={[`${base}/pull`, `${base}/queue`]} icon={<GitPullRequest size={15} />} count={repo.pulls}>
982 Pull requests
983 </SidebarLink>
984 <SidebarLink to={`${base}/agents`} also={[`${base}/sessions`, `${base}/memory`, ...soonPaths(base, "Agents")]} icon={<Bot size={15} />}>
985 Agents
986 </SidebarLink>
987 <SidebarLink to={`${base}/actions`} icon={<PlayCircle size={15} />}>
988 Workflows
989 </SidebarLink>
990 </div>
991 <Rule />
992 <div className="space-y-px">
993 {shows.has("deployments") ? (
994 <SidebarLink to={`${base}/deployments`} also={soonPaths(base, "Deployments")} icon={<Rocket size={15} />}>
995 Deployments
996 </SidebarLink>
997 ) : null}
998 <SidebarSoonLink to={`${base}/soon/logs`} also={soonPaths(base, "Observability")} icon={<Activity size={15} />} about="Logs, errors, uptime and analytics of the project's deployed apps.">
999 Observability
1000 </SidebarSoonLink>
1001 {shows.has("security") ? (
1002 <SidebarLink to={`${base}/security`} also={soonPaths(base, "Security")} icon={<ShieldCheck size={15} />}>
1003 Security
1004 </SidebarLink>
1005 ) : null}
1006 <SidebarSoonLink to={`${base}/soon/delivery`} also={soonPaths(base, "Insights")} icon={<BarChart3 size={15} />} about="Delivery metrics, costs and the work agents do.">
1007 Insights
1008 </SidebarSoonLink>
1009 </div>
1010 {(repo.settings ?? shows.has("settings")) && (
1011 <>
1012 <Rule />
1013 <SidebarLink to={`${base}/settings`} icon={<Settings size={15} />} drill>
1014 Settings
1015 </SidebarLink>
1016 </>
1017 )}
1018 </nav>
1019 );
1020}
1021
1022/**
1023 * A project's settings, drilled into from its list: what is about running
1024 * it, then its agents, then its code and who can reach it. The way back
1025 * leads to the project.
1026 */
1027function RepoSettingsMenu({ repo }: { repo: MenuRepo }) {
1028 const base = `/${repo.namespace}/${repo.name}`;
1029 // Each page shows to the roles that can use it, once the role is known.
1030 const shows = (page: string) => !repo.can || repo.can[SETTINGS_CAPABILITY[page] ?? "administer"];
1031 const running = shows("deployments");
1032 const agents = shows("agents") || shows("guardrails");
1033 return (
1034 <nav aria-label={`${repo.namespace}/${repo.name} settings`} className={PANEL}>
1035 <BackRow to={base} label="Settings" context={`${repo.namespace}/${repo.name}`} />
1036 {shows("") && (
1037 <div className="mt-2 space-y-px">
1038 <SidebarLink to={`${base}/settings`} end icon={<Settings size={15} />}>
1039 General
1040 </SidebarLink>
1041 </div>
1042 )}
1043 {running && (
1044 <>
1045 {shows("") && <Rule />}
1046 <div className={shows("") ? "space-y-px" : "mt-2 space-y-px"}>
1047 <SidebarLink to={`${base}/settings/deployments`} icon={<Rocket size={15} />}>
1048 Deployments
1049 </SidebarLink>
1050 <SidebarLink to={`${base}/settings/domains`} icon={<Globe size={15} />}>
1051 Domains
1052 </SidebarLink>
1053 <SidebarLink to={`${base}/settings/dependencies`} icon={<Network size={15} />}>
1054 Dependencies
1055 </SidebarLink>
1056 </div>
1057 </>
1058 )}
1059 {agents && (
1060 <>
1061 <Rule />
1062 <div className="space-y-px">
1063 {shows("agents") && (
1064 <SidebarLink to={`${base}/settings/agents`} icon={<Bot size={15} />}>
1065 Agents
1066 </SidebarLink>
1067 )}
1068 {shows("guardrails") && (
1069 <SidebarLink to={`${base}/settings/guardrails`} icon={<ShieldCheck size={15} />}>
1070 Guardrails
1071 </SidebarLink>
1072 )}
1073 </div>
1074 </>
1075 )}
1076 <Rule />
1077 <div className="space-y-px">
1078 {shows("repository") && (
1079 <SidebarLink to={`${base}/settings/repository`} icon={<BookMarked size={15} />}>
1080 Repository
1081 </SidebarLink>
1082 )}
1083 {shows("access") && (
1084 <SidebarLink to={`${base}/settings/access`} icon={<Users size={15} />}>
1085 Access
1086 </SidebarLink>
1087 )}
1088 {shows("branches") && (
1089 <SidebarLink to={`${base}/settings/branches`} icon={<GitBranch size={15} />}>
1090 Branches and merging
1091 </SidebarLink>
1092 )}
1093 {shows("secrets") && (
1094 <SidebarLink to={`${base}/settings/secrets`} icon={<Lock size={15} />}>
1095 Secrets and variables
1096 </SidebarLink>
1097 )}
1098 {shows("runners") && (
1099 <SidebarLink to={`${base}/settings/runners`} icon={<ServerCog size={15} />}>
1100 Runners
1101 </SidebarLink>
1102 )}
1103 {shows("webhooks") && (
1104 <SidebarLink to={`${base}/settings/webhooks`} icon={<Webhook size={15} />}>
1105 Webhooks
1106 </SidebarLink>
1107 )}
1108 </div>
1109 </nav>
1110 );
1111}
1112
1113/** Your own settings, drilled into from Your settings: one page each. */
1114function AccountSettingsMenu({ username }: { username: string }) {
1115 const link = (page: AccountSettingsPage, icon: ReactNode) => (
1116 <SidebarLink to={`/settings/${page}`} icon={icon}>
1117 {ACCOUNT_SETTINGS[page].title}
1118 </SidebarLink>
1119 );
1120 return (
1121 <nav aria-label="Your settings" className={PANEL}>
1122 <BackRow to="/" label="Your settings" context={username} />
1123 <div className="mt-2 space-y-px">
1124 {link("profile", <CircleUserRound size={15} />)}
1125 {link("emails", <Mail size={15} />)}
1126 {link("invites", <Ticket size={15} />)}
1127 </div>
1128 <Rule />
1129 <div className="space-y-px">
1130 {link("keys", <Fingerprint size={15} />)}
1131 {link("tokens", <KeyRound size={15} />)}
1132 </div>
1133 <Rule />
1134 <div className="space-y-px">
1135 {link("github", <GithubMark className="size-[15px]" />)}
1136 {link("applications", <Plug size={15} />)}
1137 </div>
1138 <Rule />
1139 <div className="space-y-px">
1140 {link("security-log", <History size={15} />)}
1141 </div>
1142 </nav>
1143 );
1144}
1145
1146/**
1147 * Signing in and signing up, in place of the account for a visitor. Signing
1148 * in brings them back to the page they are on.
1149 */
1150/** Help, status and the fine print under a visitor's sign-in buttons. */
1151function VisitorLinks() {
1152 const status = useSiteStatus();
1153 const quiet = `${LEGAL_LINK} hover:bg-raised hover:text-fg focus-visible:ring-2 focus-visible:ring-accent/60`;
1154 const dot = (
1155 <span aria-hidden="true" className="text-[0.625rem] text-line-strong">
1156 ·
1157 </span>
1158 );
1159 return (
1160 // Two short rows, so a narrow sidebar never starts a line with a dot.
1161 <nav aria-label="About g1t" className="pt-0.5">
1162 <div className="flex items-center gap-0.5">
1163 <a href={STATUS_URL} className={`${quiet} gap-1.5`}>
1164 <StatusDot state={status?.overall.state ?? null} />
1165 Status
1166 </a>
1167 {dot}
1168 <Link to="/support" className={quiet}>
1169 Support
1170 </Link>
1171 </div>
1172 <div className="flex items-center gap-0.5">
1173 {LEGAL_LINKS.map(([label, to], index) => (
1174 <span key={to} className="flex items-center gap-0.5">
1175 {index > 0 && dot}
1176 <Link to={to} className={quiet}>
1177 {label}
1178 </Link>
1179 </span>
1180 ))}
1181 </div>
1182 </nav>
1183 );
1184}
1185
1186function VisitorPanel() {
1187 const { pathname, search } = useLocation();
1188 const signUp = useSignUpCopy();
1189 return (
1190 <div className="space-y-2">
1191 <p className="px-1 text-xs text-muted">Sign in to open issues, review pull requests and run agents.</p>
1192 <div className="grid grid-cols-2 gap-2">
1193 <Link
1194 to={withNext("/login", pathname + search)}
1195 className="flex h-9 items-center justify-center gap-1.5 rounded-md border border-line text-[0.8125rem] font-medium text-fg/90 transition-colors hover:border-line-strong hover:bg-raised hover:text-fg"
1196 >
1197 <LogIn size={14} />
1198 Sign in
1199 </Link>
1200 <Link
1201 to={withNext("/register", pathname + search)}
1202 className="flex h-9 items-center justify-center rounded-md bg-fg text-[0.8125rem] font-medium text-bg transition-colors hover:bg-white"
1203 >
1204 {signUp.primary}
1205 </Link>
1206 </div>
1207 <VisitorLinks />
1208 </div>
1209 );
1210}
1211
1212function Sidebar({
1213 user,
1214 shell,
1215 missing = false,
1216 onFind,
1217 onClose,
1218}: {
1219 user: User | null;
1220 shell: ShellData;
1221 /** The page is a 404: the address names nothing the viewer can see. */
1222 missing?: boolean;
1223 onFind: () => void;
1224 /** In the sheet on a small screen: closing it, at the end of the top row. */
1225 onClose?: () => void;
1226}) {
1227 const ws = shell.workspace;
1228 const { pathname } = useLocation();
1229 const going = useNavigation().location?.pathname;
1230 // Where the sidebar is drilled to follows the page being gone to, so it
1231 // moves as the link is followed, not once the page arrives.
1232 const target = going ?? pathname;
1233 // On a 404, the address is not a place: no list is drilled into from it,
1234 // except the project's own when the project is real and visible and only
1235 // something inside it is missing (a file, a commit, an issue).
1236 const lost = missing && going == null;
1237 const inSettings = !lost && ws != null && SETTINGS_PAGE.exec(target)?.[1]?.toLowerCase() === ws.slug;
1238 const inAccount = !lost && target === "/settings" || target.startsWith("/settings/");
1239 const active = shell.repo;
1240 // In a repository, or on the way into one, its own list.
1241 const repoPath = /^\/([^/]+)\/([^/-][^/]*)(\/|$)/.exec(target);
1242 const reserved = new Set(["settings", "explore", "search", "new", "u", "pricing", "avatars", "workspaces", "login", "logout", "register", "verify", "forgot", "reset", "device", "oauth", "policies", "security", "support", "status", "invite", "inbox", ".well-known"]);
1243 // An invitation to a repository is answered before its menu means anything.
1244 const inRepo =
1245 repoPath != null &&
1246 !reserved.has(repoPath[1]) &&
1247 repoPath[2] !== "-" &&
1248 !/^\/[^/]+\/[^/]+\/invitations\/?$/.test(target) &&
1249 (!lost || sameRepo(active, { namespace: repoPath[1]!, name: repoPath[2]! }));
1250 // A project's settings, one level further in.
1251 const inRepoSettings = inRepo && REPO_SETTINGS_PAGE.test(target);
1252 // The repository the menu is for: the one loaded if it is the one being
1253 // gone to, else what the address says, at once.
1254 const targetRepo = inRepo && repoPath ? { namespace: repoPath[1], name: repoPath[2] } : null;
1255 const guessed: MenuRepo | null = targetRepo
1256 ? sameRepo(active, targetRepo)
1257 ? active
1258 : {
1259 ...targetRepo,
1260 member: (user?.workspaces ?? []).some((m) => m.slug === targetRepo.namespace.toLowerCase()),
1261 }
1262 : null;
1263 // The viewer's role there, from the repository's page once it has loaded.
1264 const page = useRouteLoaderData("routes/repo/layout") as
1265 | { repo?: { namespace: string; name: string }; access?: ViewerAccess }
1266 | undefined;
1267 const menuRepo: MenuRepo | null =
1268 guessed && page?.access && page.repo && sameRepo(page.repo, guessed)
1269 ? { ...guessed, member: page.access.insider, settings: seesSettings(page.access), can: page.access.can }
1270 : guessed;
1271
1272 // The way from the main list to the one shown.
1273 const trail: Level[] = [{ key: "main", node: <MainMenu user={user} shell={shell} /> }];
1274 if (user && inAccount) {
1275 trail.push({ key: "account", node: <AccountSettingsMenu username={user.username} /> });
1276 } else if (ws && inSettings) {
1277 trail.push({ key: `settings:${ws.slug}`, node: <SettingsMenu slug={ws.slug} owner={ws.role === "owner"} /> });
1278 } else if (menuRepo) {
1279 const key = `repo:${menuRepo.namespace}/${menuRepo.name}`.toLowerCase();
1280 // Out of a project: to its workspace's projects when they are yours.
1281 const home = (user?.workspaces ?? []).find((m) => m.slug === menuRepo.namespace.toLowerCase());
1282 const back = !user
1283 ? { to: "/explore", label: "Explore" }
1284 : home
1285 ? { to: `/${home.slug}/-/projects`, label: "All projects" }
1286 : { to: "/", label: "Mission control" };
1287 trail.push({
1288 key,
1289 node: (
1290 <RepoMenu
1291 repo={menuRepo}
1292 isPrivate={[...shell.repos, ...(shell.shared ?? [])].some((repo) => sameRepo(repo, menuRepo) && repo.isPrivate)}
1293 back={back}
1294 />
1295 ),
1296 });
1297 if (inRepoSettings) trail.push({ key: `${key}:settings`, node: <RepoSettingsMenu repo={menuRepo} /> });
1298 }
1299
1300 return (
1301 <div className="flex h-full flex-col">
1302 {/* The same height and rule as the top bar, so the two read as one line. */}
1303 <div className="flex h-14 shrink-0 items-center gap-1 border-b border-line pr-2 pl-2.5">
1304 {user ? (
1305 <>
1306 {/* The 1 alone beside the workspace: a square hover the height of the
1307 switcher, the mark as tall as the workspace avatar. */}
1308 <Link to="/" aria-label="g1t home" className="flex size-9 shrink-0 items-center justify-center rounded-md transition-colors hover:bg-raised">
1309 <Mark tight className="h-4 w-auto" />
1310 </Link>
1311 <span className="shrink-0 text-line-strong" aria-hidden="true">
1312 /
1313 </span>
1314 <WorkspaceSwitcher user={user} shell={shell} />
1315 </>
1316 ) : (
1317 <Link to="/" aria-label="g1t home" className="mr-auto flex h-9 items-center rounded-md px-2 transition-colors hover:bg-raised">
1318 <Logo className="text-[1.25rem]" />
1319 </Link>
1320 )}
1321 {onClose && (
1322 <button
1323 type="button"
1324 aria-label="Close menu"
1325 onClick={onClose}
1326 className="flex size-9 shrink-0 items-center justify-center rounded-md text-faint hover:bg-raised hover:text-fg"
1327 >
1328 <X size={16} />
1329 </button>
1330 )}
1331 </div>
1332 <div className="px-2 pt-3">
1333 <button
1334 type="button"
1335 onClick={onFind}
1336 className="flex h-9 w-full items-center gap-2 rounded-md bg-surface px-2.5 text-[0.8125rem] text-faint ring-1 ring-line transition-colors hover:text-muted hover:ring-line-strong"
1337 >
1338 <Search size={14} />
1339 <span className="grow text-left">Search or jump to…</span>
1340 <PaletteKey className="rounded bg-raised px-1.5 font-mono text-[0.625rem] text-muted ring-1 ring-line" />
1341 </button>
1342 </div>
1343 <Drill trail={trail} />
1344 {/* The account, or signing in, as one row at the very bottom. */}
1345 <div className="shrink-0 border-t border-line p-2">
1346 {user ? <AccountMenu user={user} /> : <VisitorPanel />}
1347 </div>
1348 </div>
1349 );
1350}
1351
1352/** Words for the sections a path can end in. */
1353const SECTIONS: Record<string, string> = {
1354 issues: "Issues",
1355 milestones: "Milestones",
1356 labels: "Labels",
1357 pulls: "Pull requests",
1358 queue: "Merge queue",
1359 commits: "Commits",
1360 plans: "Outcomes",
1361 actions: "Workflows",
1362 soon: "Soon",
1363 deployments: "Deployments",
1364 repository: "Repository",
1365 access: "Access",
1366 invitations: "Invitation",
1367 repositories: "Repositories",
1368 branches: "Branches",
1369 tags: "Tags",
1370 compare: "Compare",
1371 dependencies: "Dependencies",
1372 code: "Files",
1373 secrets: "Secrets and variables",
1374 settings: "Settings",
1375 people: "People",
1376 projects: "Projects",
1377 teams: "Teams",
1378 tokens: "Access tokens",
1379 usage: "Usage",
1380 billing: "Billing and plans",
1381 integrations: "Integrations",
1382 webhooks: "Webhooks",
1383 domains: "Domains",
1384 guardrails: "Guardrails",
1385 audit: "Audit log",
1386 tree: "Files",
1387 blob: "Files",
1388 agents: "Agents",
1389 context: "Context",
1390 memory: "Memory",
1391 security: "Security",
1392 packages: "Packages",
1393 runners: "Runners",
1394 workflows: "Workflows",
1395 observability: "Observability",
1396 insights: "Insights",
1397 sessions: "Sessions",
1398};
1399
1400/** Where the page is, as a trail of links: workspace / repository / section. */
1401function Breadcrumbs({ pathname, missing, repo }: { pathname: string; missing?: boolean; repo?: ShellData["repo"] }) {
1402 // A 404 names nothing from the address, unless the project is real and
1403 // visible and only something inside it is missing.
1404 const visibleRepo = /^\/([^/]+)\/([^/-][^/]*)(\/|$)/.exec(pathname);
1405 if (missing && !(visibleRepo && sameRepo(repo ?? null, { namespace: visibleRepo[1]!, name: visibleRepo[2]! }))) {
1406 return <span className="text-sm font-medium">Not found</span>;
1407 }
1408 const parts = pathname.split("/").filter(Boolean);
1409 const reserved = ["settings", "explore", "new", "search", "workspaces", "policies", "security", "support", "status", "invite", "inbox"];
1410 if (parts.length === 0) return <span className="text-sm font-medium">Mission control</span>;
1411 // Your settings: Settings / Emails.
1412 if (parts[0] === "settings") {
1413 const page = accountSettingsPage(pathname);
1414 return <Trail trail={[{ label: "Settings", to: FIRST_SETTINGS_PAGE }, ...(page ? [{ label: ACCOUNT_SETTINGS[page].title, to: `/settings/${page}` }] : [])]} />;
1415 }
1416 if (reserved.includes(parts[0]!)) {
1417 const words: Record<string, string> = {
1418 settings: "Account",
1419 explore: "Explore",
1420 new: "New project",
1421 search: "Search",
1422 workspaces: "New workspace",
1423 policies: "Policies",
1424 security: "Security",
1425 support: "Support",
1426 status: "Status",
1427 invite: "Invite",
1428 inbox: "Inbox",
1429 };
1430 return <span className="text-sm font-medium">{words[parts[0]!]}</span>;
1431 }
1432 // A person's profile, by their handle.
1433 if (parts[0] === "u" && parts[1]) {
1434 return <span className="truncate font-mono text-[0.8125rem] font-medium">@{parts[1]}</span>;
1435 }
1436 const [owner, second, third, fourth] = parts;
1437 const trail: Crumb[] = [{ label: owner!, to: `/${owner}`, mono: true }];
1438 if (second === "-") {
1439 const page = `/${owner}/-/${third}`;
1440 if (third && SETTINGS_PAGE.test(page)) {
1441 trail.push({ label: "Settings", to: `/${owner}/-/settings` });
1442 trail.push({ label: third === "settings" ? "General" : (SECTIONS[third] ?? third), to: page });
1443 } else if (third) trail.push({ label: SECTIONS[third] ?? third, to: page });
1444 } else if (second) {
1445 const repo = `/${owner}/${second}`;
1446 trail.push({ label: second, to: repo, mono: true });
1447 if (third === "pull" && fourth) trail.push({ label: `Pull request #${fourth}`, short: `#${fourth}`, to: `${repo}/pull/${fourth}` });
1448 else if (third === "issues" && fourth && fourth !== "new") trail.push({ label: `Issue #${fourth}`, short: `#${fourth}`, to: `${repo}/issues/${fourth}` });
1449 else if (third === "commit" && fourth) trail.push({ label: fourth.slice(0, 7), to: `${repo}/commit/${fourth}`, mono: true });
1450 else if (third && SECTIONS[third]) {
1451 trail.push({ label: SECTIONS[third]!, to: `${repo}/${third}` });
1452 // A settings page names which one: Settings / Secrets and variables.
1453 if (third === "settings" && fourth && SECTIONS[fourth]) {
1454 trail.push({ label: fourth === "branches" ? "Branches and merging" : SECTIONS[fourth]!, to: `${repo}/settings/${fourth}` });
1455 }
1456 }
1457 }
1458 return <Trail trail={trail} />;
1459}
1460
1461/** One link of the trail; `short` is what a phone shows when it is the page itself. */
1462type Crumb = { label: string; to: string; mono?: boolean; short?: string };
1463
1464/**
1465 * The trail of links. On a phone there is room for one: the page itself,
1466 * with a way back to where it sits; the whole trail from a wider screen up.
1467 */
1468function Trail({ trail }: { trail: Crumb[] }) {
1469 const up = trail.length > 1 ? trail[trail.length - 2]! : null;
1470 return (
1471 <nav aria-label="Where you are" className="flex min-w-0 items-center gap-1.5 text-sm">
1472 {up && (
1473 <Link
1474 to={up.to}
1475 prefetch="intent"
1476 aria-label={`Back to ${up.label}`}
1477 className="-ml-1 flex size-8 shrink-0 items-center justify-center rounded-md text-muted transition-colors hover:bg-raised hover:text-fg sm:hidden"
1478 >
1479 <ChevronLeft size={16} />
1480 </Link>
1481 )}
1482 {trail.map((crumb, index) => {
1483 const last = index === trail.length - 1;
1484 return (
1485 <span key={index} className={`min-w-0 items-center gap-1.5 ${last ? "flex" : "hidden sm:flex"}`}>
1486 {index > 0 && <span className="hidden text-line-strong sm:inline">/</span>}
1487 <Link
1488 to={crumb.to}
1489 prefetch="intent"
1490 aria-current={last ? "page" : undefined}
1491 className={`truncate rounded px-1 py-0.5 transition-colors hover:bg-raised ${
1492 last ? "font-medium text-fg" : "text-muted hover:text-fg"
1493 } ${crumb.mono ? "font-mono text-[0.8125rem]" : ""}`}
1494 >
1495 {last && crumb.short ? (
1496 <>
1497 <span className="sm:hidden">{crumb.short}</span>
1498 <span className="hidden sm:inline">{crumb.label}</span>
1499 </>
1500 ) : (
1501 crumb.label
1502 )}
1503 </Link>
1504 </span>
1505 );
1506 })}
1507 </nav>
1508 );
1509}
1510
1511type Command = PaletteCommand;
1512
1513/** Everything the palette can jump to, from what the sidebar already knows. */
1514function commandsFor(user: User | null, shell: ShellData, here: string, signUpLabel = "Sign up"): Command[] {
1515 if (!user) return visitorCommands(shell, here, signUpLabel);
1516 const commands: Command[] = [
1517 { label: "Mission control", to: "/", icon: <House size={15} /> },
1518 ...(shell.repos.length > 0
1519 ? [{ label: "Put an agent on it", hint: "Open an issue and assign g1t", to: "/?agent=new", icon: <Sparkles size={15} /> }]
1520 : []),
1521 { label: "Explore repositories", to: "/explore", icon: <Compass size={15} /> },
1522 { label: "Search g1t", hint: "Repositories, code, issues, people", to: "/search", icon: <Search size={15} /> },
1523 { label: "Inbox", hint: "What needs you", to: "/inbox", icon: <Bell size={15} /> },
1524 { label: "New project", to: "/new", icon: <Plus size={15} /> },
1525 { label: "New workspace", to: "/workspaces/new", icon: <Plus size={15} /> },
1526 { label: "Your settings", to: FIRST_SETTINGS_PAGE, icon: <Settings size={15} /> },
1527 ...(Object.keys(ACCOUNT_SETTINGS) as AccountSettingsPage[])
1528 .filter((page) => page !== "profile")
1529 .map((page) => ({ label: ACCOUNT_SETTINGS[page].title, hint: "Your settings", to: `/settings/${page}`, icon: <Settings size={15} /> })),
1530 ];
1531 const repo = shell.repo;
1532 if (repo) {
1533 const base = `/${repo.namespace}/${repo.name}`;
1534 const name = `${repo.namespace}/${repo.name}`;
1535 commands.unshift(
1536 { label: "Overview", hint: name, to: base, icon: <LayoutGrid size={15} /> },
1537 { label: "Code", hint: name, to: `${base}/code`, icon: <Code2 size={15} /> },
1538 { label: "Issues", hint: name, to: `${base}/issues`, icon: <CircleDot size={15} /> },
1539 { label: "New issue", hint: name, to: `${base}/issues/new`, icon: <Plus size={15} /> },
1540 ...(repo.member
1541 ? [{ label: `Put an agent on ${repo.name}`, hint: name, to: `${base}/issues/new?agent=1`, icon: <Sparkles size={15} /> }]
1542 : []),
1543 { label: "Pull requests", hint: name, to: `${base}/pulls`, icon: <GitPullRequest size={15} /> },
1544 { label: "Commits", hint: name, to: `${base}/commits`, icon: <History size={15} /> },
1545 ...(repo.member
1546 ? [
1547 { label: "Plan work", hint: name, to: `${base}/plans`, icon: <ListTree size={15} /> },
1548 { label: "Deployments", hint: name, to: `${base}/deployments`, icon: <Rocket size={15} /> },
1549 { label: "Secrets and variables", hint: name, to: `${base}/settings/secrets`, icon: <Lock size={15} /> },
1550 { label: "Project settings", hint: name, to: `${base}/settings`, icon: <Settings size={15} /> },
1551 { label: "Repository settings", hint: name, to: `${base}/settings/repository`, icon: <Settings size={15} /> },
1552 ]
1553 : []),
1554 );
1555 }
1556 for (const membership of user.workspaces ?? []) {
1557 commands.push(
1558 { label: displayName(membership), hint: `Workspace · ${membership.slug}`, to: `/${membership.slug}`, icon: <Avatar name={membership.slug} image={membership.avatar} size={15} square /> },
1559 { label: "All projects", hint: membership.slug, to: `/${membership.slug}/-/projects`, icon: <LayoutGrid size={15} /> },
1560 { label: "People", hint: membership.slug, to: `/${membership.slug}/-/people`, icon: <Users size={15} /> },
1561 { label: "Usage", hint: membership.slug, to: `/${membership.slug}/-/usage`, icon: <BarChart3 size={15} /> },
1562 { label: "Billing and plans", hint: `${membership.slug} · Settings`, to: `/${membership.slug}/-/billing`, icon: <CreditCard size={15} /> },
1563 { label: "Access tokens", hint: `${membership.slug} · Settings`, to: `/${membership.slug}/-/tokens`, icon: <KeyRound size={15} /> },
1564 { label: "Integrations", hint: membership.slug, to: `/${membership.slug}/-/integrations`, icon: <Plug size={15} /> },
1565 );
1566 }
1567 for (const listed of shell.repos) {
1568 commands.push({
1569 label: listed.title ?? listed.name,
1570 hint: `${listed.namespace} · Project`,
1571 to: `/${listed.namespace}/${listed.name}`,
1572 icon: <Box size={15} />,
1573 });
1574 }
1575 // "Put an agent on …": one per project, after the projects themselves.
1576 for (const listed of shell.repos) {
1577 if (repo && listed.namespace === repo.namespace && listed.name === repo.name) continue;
1578 commands.push({
1579 label: `Put an agent on ${listed.title ?? listed.name}`,
1580 hint: `${listed.namespace}/${listed.name}`,
1581 to: `/${listed.namespace}/${listed.name}/issues/new?agent=1`,
1582 icon: <Sparkles size={15} />,
1583 });
1584 }
1585 return commands;
1586}
1587
1588/** What the palette offers a visitor: browsing, the project they are in, and signing in. */
1589function visitorCommands(shell: ShellData, here: string, signUpLabel: string): Command[] {
1590 const commands: Command[] = [];
1591 const repo = shell.repo;
1592 if (repo) {
1593 const base = `/${repo.namespace}/${repo.name}`;
1594 const name = `${repo.namespace}/${repo.name}`;
1595 commands.push(
1596 { label: "Overview", hint: name, to: base, icon: <LayoutGrid size={15} /> },
1597 { label: "Code", hint: name, to: `${base}/code`, icon: <Code2 size={15} /> },
1598 { label: "Issues", hint: name, to: `${base}/issues`, icon: <CircleDot size={15} /> },
1599 { label: "Pull requests", hint: name, to: `${base}/pulls`, icon: <GitPullRequest size={15} /> },
1600 { label: "Commits", hint: name, to: `${base}/commits`, icon: <History size={15} /> },
1601 );
1602 }
1603 commands.push(
1604 { label: "Explore", hint: "Public projects", to: "/explore", icon: <Compass size={15} /> },
1605 { label: "Search g1t", hint: "Repositories, code, issues, people", to: "/search", icon: <Search size={15} /> },
1606 { label: "Pricing", to: "/pricing", icon: <CreditCard size={15} /> },
1607 { label: "Documentation", to: "https://docs.g1t.sh/", icon: <BookOpen size={15} /> },
1608 { label: "Sign in", to: withNext("/login", here), icon: <LogIn size={15} /> },
1609 { label: signUpLabel, to: withNext("/register", here), icon: <Plus size={15} /> },
1610 );
1611 return commands;
1612}
1613
1614/**
1615 * The page while the next one loads: after a moment it dims, under the
1616 * bar below, so it is plainly on its way out rather than frozen, and the
1617 * next page fades up from there. Sending a form does not dim it: the
1618 * form's button says it is working. Spread on the element holding the page.
1619 */
1620export function useLeaving() {
1621 const navigation = useNavigation();
1622 const method = navigation.formMethod?.toUpperCase();
1623 const leaving = navigation.state === "loading" && (method == null || method === "GET");
1624 return {
1625 "aria-busy": leaving || undefined,
1626 className: `transition-opacity motion-reduce:transition-none ${leaving ? "opacity-60 delay-200 duration-300" : "duration-150"}`,
1627 };
1628}
1629
1630/**
1631 * A bar across the top of the page while the next one loads, as GitHub
1632 * has: it appears at once, creeps towards the end while waiting, then fills
1633 * and fades when the page arrives.
1634 */
1635export function Progress() {
1636 const navigation = useNavigation();
1637 const busy = navigation.state !== "idle";
1638 const [width, setWidth] = useState(0);
1639 const [visible, setVisible] = useState(false);
1640 useEffect(() => {
1641 if (busy) {
1642 setVisible(true);
1643 setWidth(12);
1644 // Slows as it goes, never quite arriving until the page does.
1645 const timer = setInterval(() => setWidth((now) => now + (90 - now) * 0.12), 200);
1646 return () => clearInterval(timer);
1647 }
1648 setWidth((now) => (now > 0 ? 100 : 0));
1649 const fade = setTimeout(() => setVisible(false), 250);
1650 const reset = setTimeout(() => setWidth(0), 550);
1651 return () => {
1652 clearTimeout(fade);
1653 clearTimeout(reset);
1654 };
1655 }, [busy]);
1656 return (
1657 <div
1658 aria-hidden="true"
1659 className={`pointer-events-none fixed inset-x-0 top-0 z-[60] h-[3px] transition-opacity duration-300 ${
1660 visible ? "opacity-100" : "opacity-0"
1661 }`}
1662 >
1663 <div
1664 className="h-full bg-accent shadow-[0_0_10px_var(--color-accent)] transition-[width] duration-200 ease-out"
1665 style={{ width: `${width}%` }}
1666 />
1667 </div>
1668 );
1669}
1670
1671/**
1672 * The app: a sidebar with the workspace, its repositories and the sections
1673 * of the one being looked at; a slim bar with search and the account; and
1674 * the page. A visitor who is not signed in gets the same frame, with
1675 * Explore and Search in place of the workspace, and signing in in place of
1676 * the account.
1677 */
1678export function AppShell({
1679 user,
1680 shell,
1681 missing = false,
1682 banner,
1683 children,
1684}: {
1685 user: User | null;
1686 shell: ShellData;
1687 /** The page is a 404 (see Sidebar). */
1688 missing?: boolean;
1689 banner?: ReactNode;
1690 children: ReactNode;
1691}) {
1692 const { pathname, search } = useLocation();
1693 const [drawer, setDrawer] = useState(false);
1694 const [palette, setPalette] = useState(false);
1695 const here = pathname + search;
1696 const signUpLabel = useSignUpCopy().primary;
1697 const commands = useMemo(() => commandsFor(user, shell, here, signUpLabel), [user, shell, here, signUpLabel]);
1698
1699 // A new page closes the drawer on small screens.
1700 useEffect(() => setDrawer(false), [pathname]);
1701 // Mission control's code, fetched while the browser is idle, so going
1702 // home never waits on it (routes/home.tsx).
1703 useEffect(() => {
1704 if (!user) return;
1705 const load = () => void import("./mission-control").catch(() => undefined);
1706 const idle = (window as { requestIdleCallback?: (callback: () => void) => number }).requestIdleCallback;
1707 if (idle) idle(load);
1708 else setTimeout(load, 1500);
1709 }, [user]);
1710 usePaletteShortcut(() => setPalette((open) => !open));
1711 const leaving = useLeaving();
1712
1713 return (
1714 // The phone's menu is a sheet: a dialog that holds focus, closes on
1715 // Escape or a tap outside, and gives focus back to the menu button.
1716 <Sheet open={drawer} onOpenChange={setDrawer}>
1717 <div className="min-h-screen">
1718 <Progress />
1719 <aside className="fixed inset-y-0 left-0 z-40 hidden w-64 border-r border-line bg-[color-mix(in_srgb,var(--color-surface)_70%,var(--color-bg))] lg:block">
1720 <Sidebar user={user} shell={shell} missing={missing} onFind={() => setPalette(true)} />
1721 </aside>
1722 <SheetContent side="left" showClose={false} aria-describedby={undefined} className="w-72 max-w-[85vw] sm:max-w-72 lg:hidden">
1723 <SheetTitle className="sr-only">Menu</SheetTitle>
1724 <Sidebar
1725 user={user}
1726 shell={shell}
1727 missing={missing}
1728 onFind={() => {
1729 setDrawer(false);
1730 setPalette(true);
1731 }}
1732 onClose={() => setDrawer(false)}
1733 />
1734 </SheetContent>
1735
1736 <div className="flex min-h-screen min-w-0 flex-col lg:pl-64">
1737 <header className="sticky top-0 z-30 flex h-14 items-center gap-3 border-b border-line bg-bg/85 px-4 backdrop-blur sm:px-6">
1738 <SheetTrigger
1739 aria-label="Open menu"
1740 className="rounded-md p-1.5 text-muted hover:bg-raised hover:text-fg lg:hidden"
1741 >
1742 <Menu size={18} />
1743 </SheetTrigger>
1744 <Breadcrumbs pathname={pathname} missing={missing} repo={shell.repo} />
1745 <div className="ml-auto flex items-center gap-1.5">
1746 {/* Search lives in the sidebar ("Search or jump to"); with the sidebar folded away, this opens the same palette. */}
1747 <button
1748 type="button"
1749 aria-label="Search or jump to"
1750 onClick={() => setPalette(true)}
1751 className="flex size-9 items-center justify-center rounded-md text-muted transition-colors hover:bg-raised hover:text-fg lg:hidden"
1752 >
1753 <Search size={16} />
1754 </button>
1755 {/* All of g1t's public projects: not any one workspace's, so here, not in the sidebar. */}
1756 <NavLink
1757 to="/explore"
1758 prefetch="intent"
1759 aria-label="Explore"
1760 className={({ isActive }) =>
1761 `flex h-9 items-center gap-1.5 rounded-md px-2 text-sm transition-colors hover:bg-raised hover:text-fg sm:px-2.5 ${isActive ? "text-fg" : "text-muted"}`
1762 }
1763 >
1764 <Compass size={16} className="sm:hidden" />
1765 <span className="hidden sm:inline">Explore</span>
1766 </NavLink>
1767 <a
1768 href="https://docs.g1t.sh/"
1769 className="hidden rounded-md px-2.5 py-1.5 text-sm text-muted transition-colors hover:bg-raised hover:text-fg sm:block"
1770 >
1771 Docs
1772 </a>
1773 {user && (
1774 <>
1775 <AgentButton />
1776 <InboxBell counts={shell.inbox ?? null} />
1777 </>
1778 )}
1779 {!user ? (
1780 // The sidebar has these too, but on a phone it is folded away.
1781 <Link
1782 to={withNext("/login", here)}
1783 className="flex h-9 items-center rounded-md bg-fg px-3 text-sm font-medium text-bg transition-colors hover:bg-white lg:hidden"
1784 >
1785 Sign in
1786 </Link>
1787 ) : (
1788 <>
1789 {/* Room between what comes in (the inbox) and what you make. */}
1790 <span aria-hidden="true" className="mx-1 h-5 w-px bg-line" />
1791 <DropdownMenu>
1792 <Tooltip>
1793 <TooltipTrigger asChild>
1794 <DropdownMenuTrigger
1795 aria-label="Create new"
1796 className="flex h-9 items-center gap-1 rounded-md border border-line px-2 text-fg/90 outline-none transition-colors hover:border-line-strong hover:bg-raised hover:text-fg focus-visible:ring-2 focus-visible:ring-accent data-[state=open]:bg-raised"
1797 >
1798 <Plus size={16} />
1799 <ChevronDown size={13} className="text-muted" />
1800 </DropdownMenuTrigger>
1801 </TooltipTrigger>
1802 <TooltipContent>Create new…</TooltipContent>
1803 </Tooltip>
1804 <DropdownMenuContent align="end" className="min-w-52">
1805 {shell.repo && (
1806 <>
1807 <DropdownMenuLabel className="truncate">In {shell.repo.name}</DropdownMenuLabel>
1808 <DropdownMenuItem asChild>
1809 <Link to={`/${shell.repo.namespace}/${shell.repo.name}/issues/new`}>
1810 <CircleDot />
1811 New issue
1812 </Link>
1813 </DropdownMenuItem>
1814 {shell.repo.member && (
1815 <DropdownMenuItem asChild>
1816 <Link to={`/${shell.repo.namespace}/${shell.repo.name}/plans`}>
1817 <ListTree />
1818 Plan work
1819 </Link>
1820 </DropdownMenuItem>
1821 )}
1822 <DropdownMenuSeparator />
1823 </>
1824 )}
1825 <DropdownMenuItem asChild>
1826 <Link to="/?agent=new">
1827 <Sparkles />
1828 Put an agent on it
1829 </Link>
1830 </DropdownMenuItem>
1831 <DropdownMenuItem asChild>
1832 <Link to="/new">
1833 <Box />
1834 New project
1835 </Link>
1836 </DropdownMenuItem>
1837 <DropdownMenuItem asChild>
1838 <Link to="/new/github">
1839 <GitBranch />
1840 Import from GitHub
1841 </Link>
1842 </DropdownMenuItem>
1843 <DropdownMenuSeparator />
1844 <DropdownMenuItem asChild>
1845 <Link to="/workspaces/new">
1846 <Users />
1847 New workspace
1848 </Link>
1849 </DropdownMenuItem>
1850 {/* A team in the workspace the sidebar is about, for whoever it lets create one. */}
1851 {shell.workspace &&
1852 (mayCreateTeams(shell.workspace.team_creation, shell.workspace.role) ? (
1853 <DropdownMenuItem asChild>
1854 <Link to={`/${shell.workspace.slug}/-/teams/new`}>
1855 <UsersRound />
1856 New team
1857 </Link>
1858 </DropdownMenuItem>
1859 ) : (
1860 <DropdownMenuItem disabled title="Only owners can create teams in this workspace.">
1861 <UsersRound />
1862 New team
1863 <span className="ml-auto pl-3 text-xs text-faint">Owners only</span>
1864 </DropdownMenuItem>
1865 ))}
1866 </DropdownMenuContent>
1867 </DropdownMenu>
1868 </>
1869 )}
1870 </div>
1871 </header>
1872 {banner}
1873 <main id="content" tabIndex={-1} {...leaving} className={`min-w-0 grow outline-none ${leaving.className}`}>
1874 {children}
1875 </main>
1876 </div>
1877 <CommandPalette
1878 open={palette}
1879 onOpenChange={setPalette}
1880 commands={commands}
1881 repo={shell.repo ? `${shell.repo.namespace}/${shell.repo.name}` : null}
1882 />
1883 </div>
1884 </Sheet>
1885 );
1886}