Skip to content

Where people and agents ship software together. The open-source git platform for the whole job: issues, agents, checks and deploys to the edge.

g1t.sh
2,267 linesCodeBlameRaw
1import { Activity, BarChart3, BrickWall, Building2, ChartLine, Flag, MessagesSquare, Bell, BookMarked, BookOpen, Bookmark, Blocks, Box, Check, ChevronDown, ChevronLeft, ChevronRight, CircleDot, GripVertical, CircleUserRound, Code2, Compass, CreditCard, Fingerprint, Gauge, GitBranch, GitPullRequest, Globe, History, Keyboard, KeyRound, Layers, LayoutDashboard, LayoutGrid, LifeBuoy, Lock, LogOut, Mail, MonitorCog, MonitorDown, Package, PlayCircle, Plug, Plus, Rocket, Search, ServerCog, Settings, Shapes, Shield, ShieldCheck, Scale, Smile, Sparkles, Star, House, Ticket, TrendingUp, UserPlus, UserRoundKey, Users, UsersRound, Webhook, X } from "lucide-react";
2import { Fragment, type ReactNode, useCallback, useEffect, useMemo, useRef, useState } from "react";
3import { Link, useFetcher, useLocation, useNavigation, useRouteLoaderData, useSubmit } from "react-router";
4
5import { type Abilities, type ChatSidebarEntry, type InboxCounts, type Membership, type Spike, type User, hasCodeAccess, mayCreateTeams, shownUsername } from "@g1t/contracts";
6
7import { InMain } from "./landmark";
8import { CommandPalette, type PaletteCommand, PaletteKey, usePaletteShortcut } from "./command-palette";
9import { AskButton } from "./ask-button";
10import { NotificationsBell } from "./inbox";
11import { desktopBridge, useDesktopApp, useTitleBarSearch } from "../lib/notify-client";
12import { PinButton } from "./pin-button";
13import { Hint } from "./ui/hint";
14import { Collapsible, CollapsibleContent, CollapsibleTrigger } from "./ui/collapsible";
15import {
16 Sidebar,
17 SidebarGroup,
18 SidebarGroupAction,
19 SidebarGroupContent,
20 SidebarGroupLabel,
21 SidebarHeader,
22 SidebarMenu,
23 SidebarMenuBadge,
24 SidebarMenuButton,
25 SidebarMenuItem,
26 SidebarMobile,
27 SidebarProvider,
28 SidebarSeparator,
29 SidebarTrigger,
30} from "./ui/sidebar";
31import { StatusDot, useSiteStatus } from "./footer";
32import { Logo } from "./logo";
33import { SoonPill } from "./ui";
34import { Avatar } from "./ui/avatar";
35import { Skeleton } from "./ui/skeleton";
36import { Badge } from "./ui/badge";
37import { Button } from "./ui/button";
38import { Separator } from "./ui/separator";
39import { Breadcrumb, BreadcrumbItem, BreadcrumbLink, BreadcrumbList, BreadcrumbPage, BreadcrumbSeparator } from "./ui/breadcrumb";
40import {
41 DropdownMenu,
42 DropdownMenuContent,
43 DropdownMenuGroup,
44 DropdownMenuItem,
45 DropdownMenuLabel,
46 DropdownMenuSeparator,
47 DropdownMenuTrigger,
48} from "./ui/dropdown-menu";
49import { type RoadmapItem, roadmapIn, roadmapItem } from "../lib/roadmap";
50import {
51 type BrowsedOwner,
52 type ModeKey,
53 WORKSPACE_SETTINGS_GROUPS,
54 type WorkspaceSettingsPage,
55 browsingOf,
56 homePagePath,
57 modeOf,
58 pagePath,
59 workspaceSettingsPage,
60} from "../lib/workspace-nav";
61import { setupPath } from "../lib/onboarding";
62import { ChatSidebar } from "./chat/sidebar";
63import { FoliosSidebar } from "./folios/sidebar";
64import { Rail, ShortcutsDialog, WorkspaceSwitcher, sidebarKeyLabel } from "./rail";
65import { BottomBar, isConversation, useVisualViewport } from "./mobile";
66import { useChatSidebar } from "./chat/actions";
67import { unreadTotals } from "../lib/chat";
68import { SETTINGS_CAPABILITY, type ViewerAccess, seesSettings } from "../lib/access";
69import { projectPages } from "../lib/chrome";
70import { ACCOUNT_SETTINGS, type AccountSettingsPage, FIRST_SETTINGS_PAGE, accountSettingsPage } from "../lib/account-settings";
71import { type PinnableApp, sidebarCookie } from "../lib/apps";
72import { REASON_FILTERS, inboxReason, inboxView } from "../lib/inbox";
73import { GithubMark } from "./github";
74import { STATUS_URL, statusTitle } from "../lib/status";
75import { G1T_INVITES, leftBadge } from "../lib/invites";
76import { type ShortcutProject, movedPin, recentWith } from "../lib/pins";
77import type { AccountMenuData } from "../routes/settings-menu-json";
78import { useLiveBadges } from "../lib/notify-client";
79import { OwnPresenceDot, OwnPresenceItems, StatusDialog } from "./presence";
80import { THEME_COMMANDS, ThemeMenuSwitch } from "./theme-switch";
81
82/**
83 * What the sidebar needs, worked out by the root loader. For a visitor who
84 * is not signed in there is no workspace, no projects and no usage: only
85 * the project being looked at, if they can see it.
86 */
87export type ShellData = {
88 /** The workspace the sidebar is about: the one being looked at, or their first. */
89 workspace: Membership | null;
90 /** All its projects, by name, for the palette: `name` is the slug in their address. */
91 repos: ShortcutProject[];
92 /** The person's pinned projects in it, in their order (lib/pins.ts). */
93 pinned?: ShortcutProject[];
94 /** What they opened there last, latest first, leaving out the pinned. */
95 recent?: ShortcutProject[];
96 /** Repositories shared with them in workspaces they do not belong to. */
97 shared?: { namespace: string; name: string; isPrivate: boolean }[];
98 /** The project being looked at, if any, whoever owns it. */
99 repo: {
100 namespace: string;
101 name: string;
102 member: boolean;
103 issues: number;
104 pulls: number;
105 } | null;
106 /** Where the workspace stands against its usage limit, if billing is on. */
107 limit: {
108 exposureMicros: number;
109 ceilingMicros: number | null;
110 state: "ok" | "warning" | "stopped";
111 comped: boolean;
112 } | null;
113 /** Whether g1t charges nothing for now, while it is being built out. */
114 free?: boolean;
115 /** This month's usage: charged, or at cost while g1t is free. */
116 monthUsageMicros: number | null;
117 /** Whether new compute is paused (a spend spike or a hold), and whether the viewer can answer it. */
118 compute?: { paused: string | null; spike: Spike | null; owner: boolean } | null;
119 /** What is unread in their notifications, for the rail and the bell. Absent for a visitor. */
120 inbox?: InboxCounts | null;
121 /**
122 * Chat, for the rail's badge: what is unread, and the
123 * starred and latest conversations. Null when chat did not answer in time.
124 */
125 chat?: { unread: number; mentions: number; starred?: ChatSidebarEntry[]; recent?: ChatSidebarEntry[] } | null;
126 /** The apps this person pinned to their rail in the workspace (lib/apps.ts). */
127 pins?: PinnableApp[];
128};
129
130/** Whether `pathname` is `to` or a page under it (`end`: only `to` itself), the query left aside. */
131function under(pathname: string, to: string, end = false): boolean {
132 const path = to.split("?")[0]!;
133 return pathname === path || (!end && pathname.startsWith(path.endsWith("/") ? path : `${path}/`));
134}
135
136/**
137 * Where a row is current and where it is on its way to. A row's page is
138 * current under its own address and any `also` prefix, unless the list
139 * says itself (`current`). Rows that differ by query alone (Notifications'
140 * views and reasons) are pending only when the page on its way is that
141 * row's, query and all.
142 */
143function useRowState(to: string, { end, also, current: lit }: { end?: boolean; also?: string | string[]; current?: boolean }) {
144 const { pathname } = useLocation();
145 const going = useNavigation().location;
146 const current = lit ?? (under(pathname, to, end) || [also ?? []].flat().some((prefix) => under(pathname, prefix)));
147 const pending =
148 going != null && !current && (lit === undefined ? under(going.pathname, to, end) : `${going.pathname}${going.search}` === to);
149 return { current, pending };
150}
151
152/**
153 * One row of a mode's sidebar: an icon, its words, how many it lists
154 * (`count`) and, for a row that opens a list of its own (`drill`), a
155 * chevron, always or on hover.
156 */
157function SidebarLink({
158 to,
159 icon,
160 end,
161 count,
162 also,
163 drill,
164 current: lit,
165 action,
166 bare = false,
167 children,
168}: {
169 to: string;
170 icon: ReactNode;
171 end?: boolean;
172 count?: number;
173 /** Other path prefixes under which this link is the current one. */
174 also?: string | string[];
175 /** It opens a list of its own: a chevron says so, always or on hover. */
176 drill?: boolean | "hover";
177 /** Whether it is the current row, when the list works that out itself. */
178 current?: boolean;
179 /** A small button at the row's end, beside the words (a pin). */
180 action?: ReactNode;
181 /** The row alone, for a list item that is drawn by the list (a pinned project, which drags). */
182 bare?: boolean;
183 children: ReactNode;
184}) {
185 const { current, pending } = useRowState(to, { end, also, current: lit });
186 const Item = bare ? Fragment : SidebarMenuItem;
187 return (
188 <Item>
189 <SidebarMenuButton asChild isActive={current} isPending={pending} className={action ? "pr-7" : undefined}>
190 <Link to={to} prefetch="intent" aria-current={current ? "page" : undefined}>
191 {icon}
192 <span className="min-w-0 grow truncate">{children}</span>
193 {count != null && count > 0 && <SidebarMenuBadge>{count}</SidebarMenuBadge>}
194 {drill && (
195 <ChevronRight
196 aria-hidden="true"
197 className={`-mr-0.5 size-3.5! shrink-0 text-faint transition-opacity ${drill === "hover" ? "opacity-0 group-hover/menu-button:opacity-100 group-focus-visible/menu-button:opacity-100" : ""}`}
198 />
199 )}
200 </Link>
201 </SidebarMenuButton>
202 {action}
203 </Item>
204 );
205}
206
207/**
208 * A page that is coming, as a link to its roadmap page: faint, with Soon,
209 * and marked current on any of its section's Soon pages.
210 */
211function SidebarSoonLink({
212 to,
213 also,
214 icon,
215 about,
216 current: lit,
217 children,
218}: {
219 to: string;
220 also?: string[];
221 icon: ReactNode;
222 about: string;
223 /** Whether it is the current row, when the list works that out itself. */
224 current?: boolean;
225 children: ReactNode;
226}) {
227 const { current, pending } = useRowState(to, { also, current: lit });
228 return (
229 <SidebarMenuItem>
230 <Hint label={about} side="right">
231 <SidebarMenuButton asChild variant="faint" isActive={current} isPending={pending}>
232 <Link to={to} prefetch="intent" aria-current={current ? "page" : undefined}>
233 {icon}
234 <span className="min-w-0 grow truncate">{children}</span>
235 <SoonPill />
236 </Link>
237 </SidebarMenuButton>
238 </Hint>
239 </SidebarMenuItem>
240 );
241}
242
243/** The Soon pages of a section, as paths, so its link is current on them. */
244function soonPaths(base: string, section: RoadmapItem["section"]): string[] {
245 return roadmapIn(section).map((item) => `${base}/soon/${item.key}`);
246}
247
248/** A titled group of rows: its name in small capitals, what it makes at the end, and its menu. */
249function NavGroup({
250 title,
251 action,
252 className,
253 children,
254}: {
255 title: string;
256 /** A small button at the label's end, in its row: what the group makes (a `SidebarGroupAction` with `relative top-auto right-auto`). */
257 action?: ReactNode;
258 className?: string;
259 children: ReactNode;
260}) {
261 return (
262 <SidebarGroup className={className}>
263 <div className="flex items-center justify-between gap-2 pr-1">
264 <SidebarGroupLabel asChild>
265 <h2>{title}</h2>
266 </SidebarGroupLabel>
267 {action}
268 </div>
269 <SidebarGroupContent>
270 <SidebarMenu>{children}</SidebarMenu>
271 </SidebarGroupContent>
272 </SidebarGroup>
273 );
274}
275
276/** Rows with no name over them: the first of a list, or a run between rules. */
277function NavRows({ className, children }: { className?: string; children: ReactNode }) {
278 return (
279 <SidebarGroup className={className}>
280 <SidebarGroupContent>
281 <SidebarMenu>{children}</SidebarMenu>
282 </SidebarGroupContent>
283 </SidebarGroup>
284 );
285}
286
287/** What a workspace is called where people read it: its display name, else its slug. */
288function displayName(membership: Membership): string {
289 return membership.name?.trim() || membership.slug;
290}
291
292/**
293 * The fine print, as one quiet row at the foot of the account menu and the
294 * visitor's panel: each link a full-height target, left-aligned. In the
295 * menu each is a menu item, so the arrow keys reach it.
296 */
297const LEGAL_LINKS: [string, string][] = [
298 ["Policies", "/policies"],
299 ["Privacy", "/policies/privacy"],
300 ["Security", "/security"],
301];
302const LEGAL_LINK = "flex h-7 items-center rounded px-1.5 text-xs text-faint outline-none transition-colors";
303
304function MenuLegalRow() {
305 return (
306 <div role="group" aria-label="Legal" className="flex items-center gap-0.5 px-0.5 pt-0.5">
307 {LEGAL_LINKS.map(([label, to], index) => (
308 <span key={to} className="flex items-center gap-0.5">
309 {index > 0 && (
310 <span aria-hidden="true" className="text-[0.625rem] text-line-strong">
311 ·
312 </span>
313 )}
314 <DropdownMenuItem asChild className={`${LEGAL_LINK} py-0 data-highlighted:bg-line data-highlighted:text-fg`}>
315 <Link to={to}>{label}</Link>
316 </DropdownMenuItem>
317 </span>
318 ))}
319 </div>
320 );
321}
322
323/** Status's row: the live dot and two or three words, fetched when the menu opens. */
324function StatusSummary({ open }: { open: boolean }) {
325 const status = useSiteStatus(open);
326 const words = statusTitle(status);
327 return (
328 <span className="ml-auto flex min-w-0 items-center gap-1.5 pl-2 text-xs text-faint">
329 {/* The words say it; the dot's own words for screen readers would repeat them. */}
330 <span aria-hidden="true" className="flex">
331 <StatusDot state={status?.overall.state ?? null} />
332 </span>
333 {words ? <span className="truncate">{words}</span> : <Skeleton className="h-3 w-20" />}
334 </span>
335 );
336}
337
338/** A menu row: an icon, words, and whatever sits at its end. */
339const MENU_ROW = "h-9 gap-2.5 px-2.5 text-[0.8125rem]";
340
341/**
342 * Your account, at the foot of the rail (or in the header, before you have
343 * a workspace): who you are and your status, your profile and settings,
344 * and help: the documentation, support, status and the keyboard's
345 * shortcuts; then signing out and the fine print.
346 */
347function AccountMenu({ user, side = "right" }: { user: User; side?: "right" | "bottom" }) {
348 const submit = useSubmit();
349 const [open, setOpen] = useState(false);
350 const [keys, setKeys] = useState(false);
351 // Inside the desktop app there is nothing to get.
352 const inApp = useDesktopApp();
353 // Your status's dialog: outside the menu, so the menu closes behind it.
354 const [editing, setEditing] = useState(false);
355 // Name, primary address and invites left: asked for once, as soon as the
356 // pointer or focus reaches the button, so they are there when it opens.
357 const details = useFetcher<AccountMenuData | null>({ key: "account-menu" });
358 const prefetch = () => {
359 if (details.state === "idle" && details.data === undefined) details.load("/settings/menu.json");
360 };
361 useEffect(() => {
362 if (open) prefetch();
363 // eslint-disable-next-line react-hooks/exhaustive-deps
364 }, [open]);
365 const me = details.data ?? null;
366 // Still on its way: shapes where the words will be, the same size.
367 const loading = details.data === undefined && details.state !== "idle";
368 const profile = `/u/${user.username}`;
369 return (
370 <>
371 <DropdownMenu open={open} onOpenChange={setOpen}>
372 {/* The avatar alone, with a dot that says how others see you (components/presence.tsx). */}
373 <Hint label={side === "right" ? "Your account" : undefined} side="right">
374 <DropdownMenuTrigger
375 aria-label={`Account menu for ${shownUsername(user)}`}
376 onPointerEnter={prefetch}
377 onFocus={prefetch}
378 className={
379 side === "right"
380 ? // At the foot of the rail: a 40px rounded square, as the rail's icons are.
381 "relative flex size-10 items-center justify-center rounded-[10px] outline-none transition-colors hover:bg-sidebar-accent focus-visible:ring-2 focus-visible:ring-accent data-[state=open]:bg-sidebar-accent"
382 : "relative flex rounded-full outline-none transition-transform hover:scale-[1.04] focus-visible:ring-2 focus-visible:ring-accent data-[state=open]:ring-2 data-[state=open]:ring-line-strong"
383 }
384 >
385 <Avatar name={user.username} image={user.avatar} size={side === "right" ? 40 : 28} square={side === "right"} />
386 <OwnPresenceDot ring={side === "right" ? "var(--color-rail)" : "var(--color-bg)"} className={side === "right" ? "absolute -right-1 -bottom-1" : "absolute -right-0.5 -bottom-0.5"} />
387 </DropdownMenuTrigger>
388 </Hint>
389 <DropdownMenuContent align="end" side={side} sideOffset={side === "right" ? 14 : 6} collisionPadding={8} className="w-70 p-1.5">
390 {/* Who is signed in, and a way to their profile. */}
391 <DropdownMenuItem asChild className="gap-3 px-2 py-2">
392 <Link to={profile} aria-label={`${me?.name ?? shownUsername(user)} (@${shownUsername(user)}), your profile`}>
393 <Avatar name={user.username} image={user.avatar} size={36} />
394 <span className="flex min-w-0 grow flex-col leading-tight" aria-busy={loading}>
395 {loading ? (
396 <Skeleton className="my-0.75 h-3.5 w-28" />
397 ) : (
398 <span className="truncate text-sm font-medium text-fg">{me?.name ?? shownUsername(user)}</span>
399 )}
400 <span className="truncate font-mono text-xs text-muted">@{shownUsername(user)}</span>
401 {loading ? (
402 <Skeleton className="mt-1 h-3 w-40" />
403 ) : (
404 me?.email && <span className="mt-0.5 truncate text-xs text-faint">{me.email}</span>
405 )}
406 </span>
407 </Link>
408 </DropdownMenuItem>
409 <DropdownMenuSeparator className="my-1.5" />
410 {/* Your status, away, and pausing notifications. */}
411 <DropdownMenuGroup>
412 <OwnPresenceItems className="min-h-9 py-1.5 text-[0.8125rem]" onEdit={() => setEditing(true)} />
413 </DropdownMenuGroup>
414 <DropdownMenuSeparator className="my-1.5" />
415 <DropdownMenuGroup>
416 <DropdownMenuItem asChild className={MENU_ROW}>
417 <Link to={profile}>
418 <CircleUserRound />
419 Your profile
420 </Link>
421 </DropdownMenuItem>
422 <DropdownMenuItem asChild className={MENU_ROW}>
423 <Link to={FIRST_SETTINGS_PAGE}>
424 <Settings />
425 Your settings
426 </Link>
427 </DropdownMenuItem>
428 {/* Invite a friend to g1t: word of mouth, never needed to sign up (routes/settings/invites.tsx). */}
429 <DropdownMenuItem asChild className={MENU_ROW}>
430 <Link to="/settings/invites?new">
431 <UserPlus />
432 {G1T_INVITES.action}
433 {loading && <Skeleton className="ml-auto h-4 w-12 rounded-full" />}
434 {leftBadge(me?.invites_left) && (
435 <Badge size="sm" className="ml-auto tabular-nums">
436 {leftBadge(me?.invites_left)}
437 </Badge>
438 )}
439 </Link>
440 </DropdownMenuItem>
441 {/* The app's own: starting with the computer, closing to the tray, the badge (apps/desktop). */}
442 {inApp && desktopBridge()?.openSettings && (
443 <DropdownMenuItem className={MENU_ROW} onSelect={() => desktopBridge()?.openSettings?.()}>
444 <MonitorCog />
445 Desktop app settings
446 </DropdownMenuItem>
447 )}
448 </DropdownMenuGroup>
449 <DropdownMenuSeparator className="my-1.5" />
450 {/* Auto, Light or Dark, switched in place (lib/theme.ts). */}
451 <ThemeMenuSwitch />
452 <DropdownMenuSeparator className="my-1.5" />
453 <DropdownMenuGroup>
454 <DropdownMenuItem asChild className={MENU_ROW}>
455 <a href="https://docs.g1t.sh/">
456 <BookOpen />
457 Documentation
458 </a>
459 </DropdownMenuItem>
460 <DropdownMenuItem asChild className={MENU_ROW}>
461 <Link to="/support">
462 <LifeBuoy />
463 Support
464 </Link>
465 </DropdownMenuItem>
466 <DropdownMenuItem asChild className={MENU_ROW}>
467 <a href={STATUS_URL}>
468 <Activity />
469 Status
470 <StatusSummary open={open} />
471 </a>
472 </DropdownMenuItem>
473 <DropdownMenuItem className={MENU_ROW} onSelect={() => setKeys(true)}>
474 <Keyboard />
475 Keyboard shortcuts
476 <PaletteKey className="ml-auto font-sans text-xs text-faint" />
477 </DropdownMenuItem>
478 {!inApp && (
479 <DropdownMenuItem asChild className={MENU_ROW}>
480 <Link to="/download">
481 <MonitorDown />
482 Get the desktop app
483 </Link>
484 </DropdownMenuItem>
485 )}
486 </DropdownMenuGroup>
487 <DropdownMenuSeparator className="my-1.5" />
488 {/* Submitted from here: the menu closes on select, and a button
489 that has left the page cannot submit a form. */}
490 <DropdownMenuItem className={MENU_ROW} onSelect={() => submit(null, { method: "post", action: "/logout" })}>
491 <LogOut />
492 Sign out
493 </DropdownMenuItem>
494 <DropdownMenuSeparator className="my-1.5" />
495 <MenuLegalRow />
496 </DropdownMenuContent>
497 </DropdownMenu>
498 <StatusDialog open={editing} onOpenChange={setEditing} />
499 <ShortcutsDialog open={keys} onOpenChange={setKeys} />
500 </>
501 );
502}
503
504/** A project's settings pages, which the project's menu drills into. */
505const REPO_SETTINGS_PAGE = /^\/([^/]+)\/([^/-][^/]*)\/settings(\/|$)/;
506
507/**
508 * The sidebar's lists are a stack, the way a phone pushes a screen: one
509 * drilled into slides in from the right over the full width, while the one
510 * it covers drifts a quarter of the way left and fades, both on one long
511 * ease-out, the fade quicker than the move so the two never blur together.
512 * Going back reverses it.
513 */
514const LAYER =
515 "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";
516/** One list, filling its layer. */
517const PANEL = "h-full overflow-y-auto px-1 pt-1 pb-4 scrollbar-thin";
518
519/** One list in the stack: what it is, and its rows. */
520type Level = { key: string; node: ReactNode };
521
522/** True once the page has hydrated, so what the server drew never animates in. */
523function useHydrated(): boolean {
524 const [hydrated, setHydrated] = useState(false);
525 useEffect(() => setHydrated(true), []);
526 return hydrated;
527}
528
529/**
530 * Drilling in and out of the sidebar's lists. `trail` is the way from the
531 * main list to the one shown, worked out from the address, so a link
532 * straight to a settings page opens the sidebar already drilled in, and
533 * leaving it comes back out. Lists deeper than the one shown stay in
534 * place, off to the right, so going back slides them away rather than
535 * dropping them. Moving to a list at the same depth (a workspace's settings
536 * to a project) fades the new one in where it is.
537 */
538function Drill({ trail }: { trail: Level[] }) {
539 const depth = trail.length - 1;
540 const hydrated = useHydrated();
541 const stack = useRef<Level[]>(trail);
542 const before = stack.current;
543 const within = trail.every((level, index) => before[index]?.key === level.key);
544 stack.current = within ? [...trail, ...before.slice(trail.length)] : trail;
545 const levels = stack.current;
546 // What was showing last time, to tell drilling in from moving across.
547 const shown = useRef({ depth, keys: levels.map((level) => level.key) });
548 useEffect(() => {
549 shown.current = { depth, keys: levels.map((level) => level.key) };
550 });
551 return (
552 <div className="relative min-h-0 grow overflow-hidden">
553 {levels.map((level, index) => {
554 const current = index === depth;
555 const place =
556 index < depth
557 ? "pointer-events-none -translate-x-1/4 opacity-0"
558 : current
559 ? "translate-x-0 opacity-100"
560 : "pointer-events-none translate-x-full opacity-0";
561 // A list that was not there before arrives: from the right when
562 // drilling in, in place when moving across.
563 const arriving = hydrated && current && !shown.current.keys.includes(level.key);
564 const enter = arriving
565 ? depth > shown.current.depth
566 ? "starting:translate-x-full starting:opacity-0"
567 : "starting:opacity-0"
568 : "";
569 return (
570 <div key={level.key} className={`${LAYER} ${place} ${enter}`} inert={!current} aria-hidden={!current || undefined}>
571 {level.node}
572 </div>
573 );
574 })}
575 </div>
576 );
577}
578
579/**
580 * The row at the top of a list drilled into: the list's name, which goes
581 * back out, and what it belongs to, faint at the end.
582 */
583function BackRow({ to, label, context }: { to: string; label: ReactNode; context?: ReactNode }) {
584 return (
585 <NavRows className="mt-1">
586 <SidebarMenuItem>
587 <SidebarMenuButton asChild className="gap-1.5 pl-1 font-medium text-fg">
588 <Link to={to} prefetch="intent">
589 <ChevronLeft className="text-faint transition-transform group-hover/menu-button:-translate-x-0.5 group-hover/menu-button:text-muted" />
590 <span className="min-w-0 shrink-0 truncate">{label}</span>
591 {context && <span className="ml-auto min-w-0 truncate pl-2 font-mono text-[0.6875rem] font-normal text-faint">{context}</span>}
592 </Link>
593 </SidebarMenuButton>
594 </SidebarMenuItem>
595 </NavRows>
596 );
597}
598
599/** A thin rule between groups of a list. */
600function Rule() {
601 return <SidebarSeparator className="my-1.5" />;
602}
603
604/** A quiet heading inside a group: Pinned, Recent. */
605function SidebarSubhead({ children }: { children: ReactNode }) {
606 return (
607 <SidebarGroupLabel asChild className="h-6 pt-0.5">
608 <h3>{children}</h3>
609 </SidebarGroupLabel>
610 );
611}
612
613/**
614 * The workspace's projects as the sidebar keeps them, however many there
615 * are: the person's pins in their order, what they opened last, and the
616 * way to all of them. Pins move by dragging, or with Alt and the arrow
617 * keys; the projects service keeps the order.
618 */
619function SidebarProjects({ slug, shell, current }: { slug: string; shell: ShellData; current: boolean }) {
620 const reorder = useFetcher({ key: `pins:${slug}` });
621 const saved = shell.pinned ?? [];
622 // While a new order is on its way, it shows as made.
623 const asked = reorder.formData?.get("intent") === "reorder" ? reorder.formData.getAll("slug").map(String) : null;
624 const pinned = asked
625 ? asked.map((name) => saved.find((project) => project.name === name)).filter((project): project is ShortcutProject => project != null)
626 : saved;
627 const active = shell.repo ? { namespace: shell.repo.namespace, name: shell.repo.name, isPrivate: false } : null;
628 const recent = recentWith(shell.recent ?? [], pinned, active, slug);
629 const [dragging, setDragging] = useState<number | null>(null);
630 const move = (from: number, by: number) => {
631 const next = movedPin(pinned, from, by);
632 if (!next) return;
633 const form = new FormData();
634 form.set("intent", "reorder");
635 for (const project of next) form.append("slug", project.name);
636 reorder.submit(form, { method: "post", action: `/${slug}/-/pins` });
637 };
638 // Each row pins or unpins in place: the pin shows on hover or focus, and
639 // stays shown on a pinned row's hover so it reads as "unpin".
640 const row = (project: ShortcutProject, isPinned: boolean) => (
641 <SidebarLink
642 to={`/${project.namespace}/${project.name}`}
643 icon={project.isPrivate ? <Lock /> : <Box />}
644 bare={isPinned}
645 action={
646 // At the row's end, where the row's other actions sit, and only on
647 // hover or keyboard focus: a pin clicked keeps the mouse's focus,
648 // and showing it on any focus left it lit on a row no one was over.
649 <PinButton
650 workspace={slug}
651 slug={project.name}
652 name={project.title ?? project.name}
653 pinned={isPinned}
654 small
655 className="absolute top-1/2 right-1 -translate-y-1/2 opacity-0 transition-opacity group-hover/menu-item:opacity-100 has-focus-visible:opacity-100 [@media(hover:none)]:opacity-100"
656 />
657 }
658 >
659 {project.title ?? project.name}
660 </SidebarLink>
661 );
662 return (
663 <SidebarGroup>
664 {/* The label and its button share a row, so the button stays level with the words at any text size. */}
665 <div className="flex items-center justify-between gap-2 pr-1">
666 <SidebarGroupLabel asChild>
667 <h2>Projects</h2>
668 </SidebarGroupLabel>
669 <Hint label="New project">
670 <SidebarGroupAction asChild className="relative top-auto right-auto">
671 <Link to="/new" aria-label="New project">
672 <Plus />
673 </Link>
674 </SidebarGroupAction>
675 </Hint>
676 </div>
677 <SidebarGroupContent>
678 {/* Only there once something is pinned: each row below has its own pin. */}
679 {pinned.length > 0 && (
680 <>
681 <SidebarSubhead>Pinned</SidebarSubhead>
682 <SidebarMenu aria-label="Pinned projects">
683 {pinned.map((project, index) => (
684 <SidebarMenuItem
685 key={project.name}
686 draggable={pinned.length > 1}
687 onDragStart={(event) => {
688 setDragging(index);
689 event.dataTransfer.effectAllowed = "move";
690 }}
691 onDragOver={(event) => {
692 if (dragging != null) event.preventDefault();
693 }}
694 onDrop={(event) => {
695 event.preventDefault();
696 if (dragging != null && dragging !== index) move(dragging, index - dragging);
697 setDragging(null);
698 }}
699 onDragEnd={() => setDragging(null)}
700 onKeyDown={(event) => {
701 if (!event.altKey || (event.key !== "ArrowUp" && event.key !== "ArrowDown")) return;
702 event.preventDefault();
703 move(index, event.key === "ArrowUp" ? -1 : 1);
704 }}
705 className={`group/pin ${dragging === index ? "opacity-50" : ""}`}
706 >
707 {row(project, true)}
708 {pinned.length > 1 && (
709 <Hint label="Drag, or Alt and an arrow key, to reorder" side="right">
710 <span className="absolute top-1/2 -left-2 -translate-y-1/2 cursor-grab text-faint opacity-0 transition-opacity group-hover/pin:opacity-100">
711 <GripVertical size={12} aria-hidden="true" />
712 </span>
713 </Hint>
714 )}
715 </SidebarMenuItem>
716 ))}
717 </SidebarMenu>
718 </>
719 )}
720 {recent.length > 0 && (
721 <>
722 <SidebarSubhead>Recent</SidebarSubhead>
723 <SidebarMenu aria-label="Recent projects">
724 {recent.map((project) => (
725 <Fragment key={`${project.namespace}/${project.name}`}>{row(project, false)}</Fragment>
726 ))}
727 </SidebarMenu>
728 </>
729 )}
730 <SidebarMenu className="pt-1">
731 <SidebarLink to={`/${slug}/-/projects`} icon={<LayoutGrid />} count={shell.repos.length} current={current}>
732 All projects
733 </SidebarLink>
734 </SidebarMenu>
735 </SidebarGroupContent>
736 </SidebarGroup>
737 );
738}
739
740
741/**
742 * A page a project will have that is a page of its own, not a tab: its own
743 * faint row in the project's list, leading to what it will be.
744 */
745function ProjectSoonRow({ base, feature, icon }: { base: string; feature: string; icon: ReactNode }) {
746 const item = roadmapItem(feature);
747 if (!item) return null;
748 return (
749 <SidebarSoonLink to={`${base}/soon/${item.key}`} icon={icon} about={item.summary}>
750 {item.title}
751 </SidebarSoonLink>
752 );
753}
754
755/**
756 * What the repository menu needs. Known from the address before the page's
757 * data arrives, so the menu is right from the first frame; the counts fill
758 * in once it does.
759 */
760type MenuRepo = {
761 namespace: string;
762 name: string;
763 member: boolean;
764 /** Whether they see its settings; from the repository's page once it loads. */
765 settings?: boolean;
766 /** What they may do there, once the repository's page loads. */
767 can?: Abilities;
768 issues?: number;
769 pulls?: number;
770 /** False when issues cannot be opened in it (a fork's default): Issues leaves the menu. */
771 issuesOn?: boolean;
772};
773
774function sameRepo(a: { namespace: string; name: string } | null, b: { namespace: string; name: string } | null) {
775 return (
776 a != null &&
777 b != null &&
778 a.namespace.toLowerCase() === b.namespace.toLowerCase() &&
779 a.name.toLowerCase() === b.name.toLowerCase()
780 );
781}
782
783/**
784 * A project's own list, drilled into while you are in it: everything about
785 * the project, running and its code, and nothing else, with the way back
786 * out to all of them.
787 */
788function RepoMenu({
789 repo,
790 isPrivate,
791 back,
792}: {
793 repo: MenuRepo;
794 isPrivate: boolean;
795 /** Where the way back leads: the workspace's projects, mission control, or the projects of the workspace being browsed. */
796 back: { to: string; label: string; context?: string };
797}) {
798 const base = `/${repo.namespace}/${repo.name}`;
799 // What a member sees, and what everyone who can see the project does
800 // (lib/chrome.ts).
801 const shows = new Set(projectPages(repo.member, repo.can));
802 const { current: atOverview, pending: toOverview } = useRowState(base, { end: true });
803 return (
804 <nav aria-label={`${repo.namespace}/${repo.name}`} className={PANEL}>
805 <BackRow to={back.to} label={back.label} context={back.context} />
806 <NavRows className="mt-1">
807 <SidebarMenuItem>
808 <Hint label="Overview" side="right">
809 <SidebarMenuButton asChild size="lg" isActive={atOverview} isPending={toOverview} className="gap-2 font-normal">
810 <Link to={base} prefetch="intent" aria-current={atOverview ? "page" : undefined}>
811 <span className="flex size-6 shrink-0 items-center justify-center rounded-md bg-raised text-muted ring-1 ring-line [&>svg]:size-3.5">
812 {isPrivate ? <Lock /> : <Box />}
813 </span>
814 <span className="min-w-0 truncate font-mono text-[0.8125rem]">
815 <span className="text-faint">{repo.namespace}/</span>
816 <span className="font-semibold text-fg">{repo.name}</span>
817 </span>
818 </Link>
819 </SidebarMenuButton>
820 </Hint>
821 </SidebarMenuItem>
822 </NavRows>
823 {/* A project's pages, in the order people use them. A page with more
824 than one view shows them as tabs across its top. */}
825 <Rule />
826 <NavRows>
827 <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} />}>
828 Code
829 </SidebarLink>
830 {shows.has("issues") && repo.issuesOn !== false && (
831 <SidebarLink to={`${base}/issues`} also={[`${base}/milestones`, `${base}/labels`, ...soonPaths(base, "Issues")]} icon={<CircleDot size={15} />} count={repo.issues}>
832 Issues
833 </SidebarLink>
834 )}
835 {shows.has("pulls") && (
836 <SidebarLink to={`${base}/pulls`} also={[`${base}/pull`, `${base}/work`, `${base}/queue`, `${base}/sessions`]} icon={<GitPullRequest size={15} />} count={repo.pulls}>
837 Pull requests
838 </SidebarLink>
839 )}
840 {shows.has("actions") && (
841 <SidebarLink to={`${base}/actions`} icon={<PlayCircle size={15} />}>
842 Workflows
843 </SidebarLink>
844 )}
845 </NavRows>
846 <Rule />
847 <NavRows>
848 {shows.has("deployments") ? (
849 <SidebarLink to={`${base}/deployments`} also={soonPaths(base, "Deployments")} icon={<Rocket size={15} />}>
850 Deployments
851 </SidebarLink>
852 ) : null}
853 {repo.member && <ProjectSoonRow base={base} feature="analytics" icon={<ChartLine size={15} />} />}
854 {shows.has("observability") && (
855 <SidebarLink to={`${base}/observability`} also={soonPaths(base, "Observability")} icon={<Activity size={15} />}>
856 Observability
857 </SidebarLink>
858 )}
859 {repo.member && <ProjectSoonRow base={base} feature="firewall" icon={<BrickWall size={15} />} />}
860 {repo.member && <ProjectSoonRow base={base} feature="flags" icon={<Flag size={15} />} />}
861 {shows.has("security") ? (
862 <SidebarLink to={`${base}/security`} also={soonPaths(base, "Security")} icon={<ShieldCheck size={15} />}>
863 Security
864 </SidebarLink>
865 ) : null}
866 <SidebarLink
867 to={`${base}/contributors`}
868 also={[`${base}/activity`, `${base}/stargazers`, ...soonPaths(base, "Insights")]}
869 icon={<BarChart3 size={15} />}
870 >
871 Insights
872 </SidebarLink>
873 </NavRows>
874 {(repo.settings ?? shows.has("settings")) && (
875 <>
876 <Rule />
877 <NavRows>
878 <SidebarLink to={`${base}/settings`} icon={<Settings size={15} />} drill>
879 Settings
880 </SidebarLink>
881 </NavRows>
882 </>
883 )}
884 </nav>
885 );
886}
887
888/**
889 * A project's settings, drilled into from its list: what is about running
890 * it, then its sandboxes, then its code and who can reach it. The way back
891 * leads to the project.
892 */
893function RepoSettingsMenu({ repo }: { repo: MenuRepo }) {
894 const base = `/${repo.namespace}/${repo.name}`;
895 // Each page shows to the roles that can use it, once the role is known.
896 const shows = (page: string) => !repo.can || repo.can[SETTINGS_CAPABILITY[page] ?? "administer"];
897 const running = shows("deployments");
898 const guarded = shows("guardrails");
899 return (
900 <nav aria-label={`${repo.namespace}/${repo.name} settings`} className={PANEL}>
901 <BackRow to={base} label="Settings" context={`${repo.namespace}/${repo.name}`} />
902 {shows("") && (
903 <NavRows className="mt-2">
904 <SidebarLink to={`${base}/settings`} end icon={<Settings size={15} />}>
905 General
906 </SidebarLink>
907 </NavRows>
908 )}
909 {running && (
910 <>
911 {shows("") && <Rule />}
912 <NavRows className={shows("") ? undefined : "mt-2"}>
913 <SidebarLink to={`${base}/settings/deployments`} icon={<Rocket size={15} />}>
914 Deployments
915 </SidebarLink>
916 <SidebarLink to={`${base}/settings/domains`} icon={<Globe size={15} />}>
917 Domains
918 </SidebarLink>
919 </NavRows>
920 </>
921 )}
922 {guarded && (
923 <>
924 <Rule />
925 <NavRows>
926 {shows("guardrails") && (
927 <SidebarLink to={`${base}/settings/guardrails`} icon={<ShieldCheck size={15} />}>
928 Guardrails
929 </SidebarLink>
930 )}
931 </NavRows>
932 </>
933 )}
934 <Rule />
935 <NavRows>
936 {shows("repository") && (
937 <SidebarLink to={`${base}/settings/repository`} icon={<BookMarked size={15} />}>
938 Repository
939 </SidebarLink>
940 )}
941 {shows("access") && (
942 <SidebarLink to={`${base}/settings/access`} icon={<Users size={15} />}>
943 Access
944 </SidebarLink>
945 )}
946 {shows("keys") && (
947 <SidebarLink to={`${base}/settings/keys`} icon={<KeyRound size={15} />}>
948 Deploy keys
949 </SidebarLink>
950 )}
951 {shows("branches") && (
952 <SidebarLink to={`${base}/settings/branches`} icon={<GitBranch size={15} />}>
953 Branches and merging
954 </SidebarLink>
955 )}
956 {shows("rules") && (
957 <SidebarLink to={`${base}/settings/rules`} icon={<Scale size={15} />}>
958 Rules
959 </SidebarLink>
960 )}
961 {shows("secrets") && (
962 <SidebarLink to={`${base}/settings/secrets`} icon={<Lock size={15} />}>
963 Secrets and variables
964 </SidebarLink>
965 )}
966 {shows("actions") && (
967 <SidebarLink to={`${base}/settings/actions`} icon={<PlayCircle size={15} />}>
968 Actions
969 </SidebarLink>
970 )}
971 {shows("environments") && (
972 <SidebarLink to={`${base}/settings/environments`} icon={<Layers size={15} />}>
973 Environments
974 </SidebarLink>
975 )}
976 {shows("runners") && (
977 <SidebarLink to={`${base}/settings/runners`} icon={<ServerCog size={15} />}>
978 Runners
979 </SidebarLink>
980 )}
981 {shows("webhooks") && (
982 <SidebarLink to={`${base}/settings/webhooks`} icon={<Webhook size={15} />}>
983 Webhooks
984 </SidebarLink>
985 )}
986 </NavRows>
987 </nav>
988 );
989}
990
991/** Your own settings, drilled into from Your settings: one page each. */
992function AccountSettingsMenu({ username }: { username: string }) {
993 const link = (page: AccountSettingsPage, icon: ReactNode) => (
994 <SidebarLink to={`/settings/${page}`} icon={icon}>
995 {ACCOUNT_SETTINGS[page].title}
996 </SidebarLink>
997 );
998 return (
999 <nav aria-label="Your settings" className={PANEL}>
1000 <BackRow to="/" label="Your settings" context={username} />
1001 <NavRows className="mt-2">
1002 {link("profile", <CircleUserRound size={15} />)}
1003 {link("emails", <Mail size={15} />)}
1004 {link("invites", <Ticket size={15} />)}
1005 </NavRows>
1006 <Rule />
1007 <NavRows>
1008 {link("keys", <Fingerprint size={15} />)}
1009 {link("tokens", <KeyRound size={15} />)}
1010 </NavRows>
1011 <Rule />
1012 <NavRows>
1013 {link("integrations", <Blocks size={15} />)}
1014 {link("github", <GithubMark className="size-3.75" />)}
1015 {link("applications", <Plug size={15} />)}
1016 </NavRows>
1017 <Rule />
1018 <NavRows>
1019 {link("two-factor", <ShieldCheck size={15} />)}
1020 {link("security-log", <History size={15} />)}
1021 </NavRows>
1022 </nav>
1023 );
1024}
1025
1026/**
1027 * Code's sidebar: its Overview, the projects, what spans them and what is
1028 * coming; in a project, drilled into the project's own list, and its
1029 * settings one level further in. The address says which, so a link
1030 * straight to a project opens the sidebar already drilled in.
1031 */
1032function CodeSidebar({
1033 user,
1034 shell,
1035 missing = false,
1036 browsing = null,
1037}: {
1038 user: User;
1039 shell: ShellData;
1040 /** The page is a 404: the address names nothing the viewer can see. */
1041 missing?: boolean;
1042 /** g1t beyond the viewer's workspaces (lib/workspace-nav.ts `browsingOf`): Explore's list in place of Code's. */
1043 browsing?: { owner: BrowsedOwner | null } | null;
1044}) {
1045 const ws = shell.workspace;
1046 const { pathname } = useLocation();
1047 const going = useNavigation().location?.pathname;
1048 // Where the sidebar is drilled to follows the page being gone to, so it
1049 // moves as the link is followed, not once the page arrives.
1050 const target = going ?? pathname;
1051 // On a 404, the address is not a place: no list is drilled into from it,
1052 // except the project's own when the project is real and visible and only
1053 // something inside it is missing (a file, a commit, an issue).
1054 const lost = missing && going == null;
1055 const active = shell.repo;
1056 // In a repository, or on the way into one, its own list.
1057 const repoPath = /^\/([^/]+)\/([^/-][^/]*)(\/|$)/.exec(target);
1058 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", "notifications", "inbox", ".well-known"]);
1059 // An invitation to a repository is answered before its menu means anything.
1060 const inRepo =
1061 repoPath != null &&
1062 !reserved.has(repoPath[1]) &&
1063 repoPath[2] !== "-" &&
1064 !/^\/[^/]+\/[^/]+\/invitations\/?$/.test(target) &&
1065 (!lost || sameRepo(active, { namespace: repoPath[1]!, name: repoPath[2]! }));
1066 // A project's settings, one level further in.
1067 const inRepoSettings = inRepo && REPO_SETTINGS_PAGE.test(target);
1068 // The repository the menu is for: the one loaded if it is the one being
1069 // gone to, else what the address says, at once.
1070 const targetRepo = inRepo && repoPath ? { namespace: repoPath[1], name: repoPath[2] } : null;
1071 const guessed: MenuRepo | null = targetRepo
1072 ? sameRepo(active, targetRepo)
1073 ? active
1074 : {
1075 ...targetRepo,
1076 member: (user.workspaces ?? []).some((m) => m.slug === targetRepo.namespace.toLowerCase()),
1077 }
1078 : null;
1079 // The viewer's role there, from the repository's page once it has loaded.
1080 const page = useRouteLoaderData("routes/repo/layout") as
1081 | { repo?: { namespace: string; name: string }; access?: ViewerAccess; issues?: boolean }
1082 | undefined;
1083 const menuRepo: MenuRepo | null =
1084 guessed && page?.access && page.repo && sameRepo(page.repo, guessed)
1085 ? { ...guessed, member: page.access.insider, settings: seesSettings(page.access), can: page.access.can, issuesOn: page.issues }
1086 : guessed;
1087
1088 // The way from Code's list (or Explore's, browsing) to the one shown.
1089 const main = browsing ? <BrowseMenu user={user} owner={browsing.owner} /> : ws ? <CodeMenu shell={shell} slug={ws.slug} /> : null;
1090 const trail: Level[] = [{ key: browsing ? "browse" : "main", node: main }];
1091 if (menuRepo) {
1092 const key = `repo:${menuRepo.namespace}/${menuRepo.name}`.toLowerCase();
1093 // Out of a project: to its workspace's projects when they are yours, or
1094 // when browsing, to the projects of the workspace it is in.
1095 const home = (user.workspaces ?? []).find((m) => m.slug === menuRepo.namespace.toLowerCase());
1096 const back = home
1097 ? { to: `/${home.slug}/-/projects`, label: "All projects" }
1098 : browsing
1099 ? { to: `/${menuRepo.namespace}/-/projects`, label: "Projects", context: menuRepo.namespace }
1100 : { to: ws ? `/${ws.slug}/-/overview` : "/explore", label: "Code" };
1101 trail.push({
1102 key,
1103 node: (
1104 <RepoMenu
1105 repo={menuRepo}
1106 isPrivate={[...shell.repos, ...(shell.shared ?? [])].some((repo) => sameRepo(repo, menuRepo) && repo.isPrivate)}
1107 back={back}
1108 />
1109 ),
1110 });
1111 if (inRepoSettings) trail.push({ key: `${key}:settings`, node: <RepoSettingsMenu repo={menuRepo} /> });
1112 }
1113
1114 return (
1115 <div className="flex h-full flex-col">
1116 {browsing && ws && (
1117 <>
1118 <BackToWorkspace workspace={ws} />
1119 <Rule />
1120 </>
1121 )}
1122 <ModeHeader title={browsing?.owner?.kind === "workspace" ? "Workspace" : browsing ? "Explore" : "Code"} />
1123 <Drill trail={trail} />
1124 </div>
1125 );
1126}
1127
1128/**
1129 * Browsing, the way back to the workspace you are in: its Home, at the top
1130 * of Explore's sidebar, at every level of it.
1131 */
1132function BackToWorkspace({ workspace }: { workspace: Membership }) {
1133 const name = displayName(workspace);
1134 return (
1135 <NavRows className="pt-0">
1136 <SidebarMenuItem>
1137 <SidebarMenuButton asChild className="gap-2 pl-1 font-medium text-fg">
1138 <Link to={homePagePath(workspace.slug)} prefetch="intent" aria-label={`Back to ${name}: Home`}>
1139 <ChevronLeft className="text-faint transition-transform group-hover/menu-button:-translate-x-0.5 group-hover/menu-button:text-muted" />
1140 <Avatar name={workspace.slug} image={workspace.avatar} size={18} square />
1141 <span className="min-w-0 truncate">Back to {name}</span>
1142 </Link>
1143 </SidebarMenuButton>
1144 </SidebarMenuItem>
1145 </NavRows>
1146 );
1147}
1148
1149/** Whose page is being browsed, as the page itself names them once it has loaded: a workspace's or a person's. */
1150function useBrowsedOwner(owner: BrowsedOwner | null): { name: string; avatar: string | null } | null {
1151 const workspace = useRouteLoaderData("routes/workspace/layout") as { workspace?: { slug: string; name?: string | null; avatar?: string | null } } | undefined;
1152 const person = useRouteLoaderData("routes/user") as { profile?: { username: string; displayUsername?: string | null; avatar: string | null } } | undefined;
1153 if (!owner) return null;
1154 if (owner.kind === "person") {
1155 const profile = person?.profile?.username.toLowerCase() === owner.name.toLowerCase() ? person.profile : null;
1156 return { name: `@${profile ? shownUsername(profile) : owner.name}`, avatar: profile?.avatar ?? null };
1157 }
1158 const page = workspace?.workspace?.slug.toLowerCase() === owner.name.toLowerCase() ? workspace.workspace : null;
1159 return { name: page?.name?.trim() || owner.name, avatar: page?.avatar ?? null };
1160}
1161
1162/**
1163 * Explore's list, beside g1t beyond your workspaces (lib/workspace-nav.ts
1164 * `browsingOf`): public projects across g1t, recently active and new,
1165 * search, and what you starred; then whose page this is, with their own
1166 * pages. A project of theirs drills into its own list, as in Code.
1167 */
1168function BrowseMenu({ user, owner }: { user: User; owner: BrowsedOwner | null }) {
1169 const location = useLocation();
1170 const going = useNavigation().location;
1171 const path = pagePath((going ?? location).pathname);
1172 const query = new URLSearchParams((going ?? location).search);
1173 const atExplore = path === "/explore";
1174 const fresh = atExplore && query.get("sort") === "new";
1175 const mine = `/u/${user.username}`;
1176 const atMine = path.toLowerCase() === mine.toLowerCase();
1177 const stars = atMine && query.get("tab") === "stars";
1178 const shown = useBrowsedOwner(owner);
1179 const profileTab = query.get("tab");
1180 const workspace = useRouteLoaderData("routes/workspace/layout") as
1181 | { workspace: { slug: string }; projects?: { namespace: string; name: string; title: string }[] }
1182 | undefined;
1183 if (owner?.kind === "workspace" && shown) {
1184 const base = `/${owner.name}`;
1185 const projects = workspace?.workspace.slug.toLowerCase() === owner.name.toLowerCase() ? workspace.projects ?? [] : [];
1186 return (
1187 <nav aria-label={`${owner.name} workspace`} className={PANEL}>
1188 <NavRows>
1189 <SidebarLink to={base} icon={<Avatar name={owner.name} image={shown.avatar} size={16} square />} current={false}>
1190 {shown.name}
1191 </SidebarLink>
1192 <SidebarLink to={base} icon={<LayoutDashboard size={15} />} current={path.toLowerCase() === base.toLowerCase()}>
1193 Overview
1194 </SidebarLink>
1195 </NavRows>
1196 <Rule />
1197 <NavGroup title="Projects">
1198 {projects.slice(0, 8).map((project) => (
1199 <SidebarLink key={project.name} to={`/${project.namespace}/${project.name}`} icon={<Box size={15} />}>
1200 {project.title}
1201 </SidebarLink>
1202 ))}
1203 <SidebarLink to={`${base}/-/projects`} icon={<LayoutGrid size={15} />} count={projects.length || undefined}>
1204 All projects
1205 </SidebarLink>
1206 </NavGroup>
1207 <Rule />
1208 <NavRows>
1209 <SidebarLink to={`${base}/-/packages`} icon={<Package size={15} />}>Packages</SidebarLink>
1210 </NavRows>
1211 <Rule />
1212 <NavRows>
1213 <SidebarLink to="/explore" icon={<Compass size={15} />}>Explore</SidebarLink>
1214 </NavRows>
1215 </nav>
1216 );
1217 }
1218 return (
1219 <nav aria-label="Explore" className={PANEL}>
1220 <NavRows>
1221 <SidebarLink to="/explore" icon={<Compass size={15} />} current={atExplore && !fresh}>
1222 Recently active
1223 </SidebarLink>
1224 <SidebarLink to="/explore?sort=new" icon={<Sparkles size={15} />} current={fresh}>
1225 New projects
1226 </SidebarLink>
1227 <SidebarLink to="/search" icon={<Search size={15} />} current={path === "/search"}>
1228 Search
1229 </SidebarLink>
1230 </NavRows>
1231 <Rule />
1232 <NavRows>
1233 <SidebarLink to={`${mine}?tab=stars`} icon={<Star size={15} />} current={stars}>
1234 Your stars
1235 </SidebarLink>
1236 <SidebarLink to={mine} icon={<CircleUserRound size={15} />} current={atMine && !stars}>
1237 Your profile
1238 </SidebarLink>
1239 </NavRows>
1240 {owner && shown && (
1241 <>
1242 <Rule />
1243 <NavGroup title="You are viewing">
1244 {owner.kind === "person" && (
1245 <>
1246 <SidebarLink
1247 to={`/u/${owner.name}`}
1248 icon={<Avatar name={owner.name} image={shown.avatar} size={16} />}
1249 current={profileTab !== "stars"}
1250 >
1251 {shown.name}
1252 </SidebarLink>
1253 <SidebarLink to={`/u/${owner.name}?tab=stars`} icon={<Star size={15} />} current={profileTab === "stars"}>
1254 Stars
1255 </SidebarLink>
1256 </>
1257 )}
1258 </NavGroup>
1259 </>
1260 )}
1261 </nav>
1262 );
1263}
1264
1265/**
1266 * A mode's sidebar heading: its name, quiet, under the workspace's
1267 * switcher, with what it makes at the end.
1268 */
1269export function ModeHeader({ title, action }: { title: ReactNode; action?: ReactNode }) {
1270 return (
1271 <div className="flex h-8 shrink-0 items-center gap-1 pr-2 pl-3">
1272 <SidebarGroupLabel asChild className="min-w-0 grow truncate px-1">
1273 <h2>{title}</h2>
1274 </SidebarGroupLabel>
1275 {action}
1276 </div>
1277 );
1278}
1279
1280/**
1281 * Code's own list (beside the rail): only code. Its Overview (Mission
1282 * control's code panels), the projects, what spans them, and what is
1283 * coming. The workspace's people, money and settings are elsewhere.
1284 */
1285function CodeMenu({ shell, slug }: { shell: ShellData; slug: string }) {
1286 const { pathname } = useLocation();
1287 const going = useNavigation().location?.pathname;
1288 const path = going ?? pathname;
1289 const at = (page: string) => path === `/${slug}/-/${page}` || path.startsWith(`/${slug}/-/${page}/`);
1290 const shared = shell.shared ?? [];
1291 return (
1292 <nav aria-label="Code" className={PANEL}>
1293 <NavRows>
1294 <SidebarLink to={`/${slug}/-/overview`} icon={<LayoutDashboard size={15} />} current={at("overview")}>
1295 Overview
1296 </SidebarLink>
1297 </NavRows>
1298 <Rule />
1299 <SidebarProjects slug={slug} shell={shell} current={at("projects")} />
1300 <Rule />
1301 <NavRows>
1302 <SidebarLink to={`/${slug}/-/security`} icon={<ShieldCheck size={15} />} current={at("security") && !at("security/settings")}>
1303 Security
1304 </SidebarLink>
1305 <SidebarLink to={`/${slug}/-/packages`} icon={<Package size={15} />} current={at("packages")}>
1306 Packages
1307 </SidebarLink>
1308 <SidebarLink to={`/${slug}/-/insights`} icon={<TrendingUp size={15} />} current={at("insights")}>
1309 Insights
1310 </SidebarLink>
1311 </NavRows>
1312 <Rule />
1313 <NavRows>
1314 {/* Public repositories beyond this workspace's own. */}
1315 <SidebarLink to="/explore" icon={<Compass size={15} />} current={path === "/explore" || path.startsWith("/explore/")}>
1316 Explore
1317 </SidebarLink>
1318 </NavRows>
1319 {shared.length > 0 && (
1320 <>
1321 <Rule />
1322 <NavGroup title="Shared with you">
1323 {shared.map((repo) => (
1324 <SidebarLink
1325 key={`${repo.namespace}/${repo.name}`}
1326 to={`/${repo.namespace}/${repo.name}`}
1327 icon={repo.isPrivate ? <Lock size={15} /> : <Box size={15} />}
1328 drill="hover"
1329 >
1330 <span className="font-mono text-faint">{repo.namespace}/</span>
1331 {repo.name}
1332 </SidebarLink>
1333 ))}
1334 </NavGroup>
1335 </>
1336 )}
1337 </nav>
1338 );
1339}
1340
1341/** The icon of each of Workspace mode's pages, by its key (lib/workspace-nav.ts). */
1342const WORKSPACE_PAGE_ICONS: Record<string, ReactNode> = {
1343 settings: <Settings size={15} />,
1344 members: <Users size={15} />,
1345 invitations: <Mail size={15} />,
1346 permissions: <ShieldCheck size={15} />,
1347 tokens: <KeyRound size={15} />,
1348 "personal-access-tokens": <UserRoundKey size={15} />,
1349 usage: <BarChart3 size={15} />,
1350 billing: <CreditCard size={15} />,
1351 runners: <ServerCog size={15} />,
1352 repositories: <BookMarked size={15} />,
1353 actions: <PlayCircle size={15} />,
1354 secrets: <Lock size={15} />,
1355 webhooks: <Webhook size={15} />,
1356 "chat-settings": <MessagesSquare size={15} />,
1357 emoji: <Smile size={15} />,
1358 "security-settings": <Shield size={15} />,
1359 guardrails: <Gauge size={15} />,
1360 rules: <Scale size={15} />,
1361 audit: <History size={15} />,
1362 integrations: <Plug size={15} />,
1363 ai: <Sparkles size={15} />,
1364};
1365
1366/**
1367 * A group of Workspace mode's rows that folds: its name is the button, with
1368 * a chevron that turns when it is open. The group holding the current page
1369 * is always open, and its button does nothing. Every group starts open, so
1370 * the server and the browser draw the same list.
1371 */
1372function FoldingGroup({ title, current, children }: { title: string; current: boolean; children: ReactNode }) {
1373 const [open, setOpen] = useState(true);
1374 return (
1375 <Collapsible open={open || current} onOpenChange={setOpen}>
1376 <SidebarGroup>
1377 <CollapsibleTrigger
1378 disabled={current}
1379 aria-label={`${title}: ${open || current ? "fold" : "unfold"}`}
1380 className="flex h-7 w-full shrink-0 items-center justify-between rounded-md px-2 text-[0.6875rem] font-medium tracking-wide text-faint uppercase hover:text-muted focus-visible:ring-2 focus-visible:ring-accent disabled:cursor-default disabled:text-faint data-[state=open]:[&_svg]:rotate-90"
1381 >
1382 <span>{title}</span>
1383 {!current && <ChevronRight size={12} aria-hidden="true" className="text-faint/70" />}
1384 </CollapsibleTrigger>
1385 <CollapsibleContent>
1386 <SidebarGroupContent>
1387 <SidebarMenu>{children}</SidebarMenu>
1388 </SidebarGroupContent>
1389 </CollapsibleContent>
1390 </SidebarGroup>
1391 </Collapsible>
1392 );
1393}
1394
1395/**
1396 * The Workspace mode's sidebar: the workspace's settings area, every page
1397 * one click away. Its overview, then the groups in lib/workspace-nav.ts
1398 * (General, Access, Money, Compute, Code, Chat, Security, Integrations),
1399 * each folding, the one you are in held open. Pages only owners open are
1400 * left out for members, and a group with none left goes with them.
1401 */
1402export function WorkspaceSidebar({ slug, owner }: { slug: string; owner: boolean }) {
1403 const { pathname } = useLocation();
1404 const going = useNavigation().location?.pathname;
1405 const path = going ?? pathname;
1406 const here = workspaceSettingsPage(path, slug);
1407 const overview = path === `/${slug}/-/workspace` || path.startsWith(`/${slug}/-/workspace/`);
1408 const shown = (page: WorkspaceSettingsPage) => owner || !page.owner;
1409 return (
1410 <div className="flex h-full flex-col">
1411 <ModeHeader title="Workspace" />
1412 <nav aria-label="Workspace" className={PANEL}>
1413 <NavRows>
1414 <SidebarLink to={`/${slug}/-/workspace`} icon={<LayoutGrid size={15} />} current={overview}>
1415 Overview
1416 </SidebarLink>
1417 </NavRows>
1418 {WORKSPACE_SETTINGS_GROUPS.filter((group) => group.pages.some(shown)).map((group) => (
1419 <Fragment key={group.key}>
1420 <Rule />
1421 <FoldingGroup title={group.title} current={here?.group === group.key}>
1422 {group.pages.filter(shown).map((page) => (
1423 <SidebarLink
1424 key={page.key}
1425 to={`/${slug}/-/${page.path}`}
1426 icon={WORKSPACE_PAGE_ICONS[page.key] ?? <Settings size={15} />}
1427 current={here?.page === page.key}
1428 >
1429 {page.label}
1430 </SidebarLink>
1431 ))}
1432 </FoldingGroup>
1433 </Fragment>
1434 ))}
1435 </nav>
1436 </div>
1437 );
1438}
1439
1440/**
1441 * People's sidebar: everyone in the workspace and its teams. Who belongs, and
1442 * inviting people, is the workspace's: Workspace mode's Access group.
1443 */
1444function PeopleSidebar({ slug }: { slug: string }) {
1445 const { pathname } = useLocation();
1446 const going = useNavigation().location?.pathname;
1447 const path = going ?? pathname;
1448 const at = (page: string) => path === `/${slug}/-/${page}` || path.startsWith(`/${slug}/-/${page}/`);
1449 return (
1450 <div className="flex h-full flex-col">
1451 <ModeHeader title="People" />
1452 <nav aria-label="People" className={PANEL}>
1453 <NavRows>
1454 <SidebarLink to={`/${slug}/-/people`} icon={<Users size={15} />} current={at("people")}>
1455 Everyone
1456 </SidebarLink>
1457 <SidebarLink to={`/${slug}/-/teams`} icon={<UsersRound size={15} />} current={at("teams")}>
1458 Teams
1459 </SidebarLink>
1460 </NavRows>
1461 </nav>
1462 </div>
1463 );
1464}
1465
1466/**
1467 * Notifications' sidebar: what you have not finished with, what you saved
1468 * and what is done; then why you were told, which narrows any of them.
1469 */
1470function NotificationsSidebar({ counts }: { counts: InboxCounts | null }) {
1471 const { search } = useLocation();
1472 const params = new URLSearchParams(search);
1473 const view = inboxView(params.get("view"));
1474 const reason = inboxReason(params.get("reason"));
1475 const tab = params.get("tab");
1476 const address = (changes: Record<string, string | null>) => {
1477 const merged: Record<string, string | null> = { tab, view: view === "inbox" ? null : view, reason, ...changes };
1478 const next = new URLSearchParams();
1479 for (const [name, value] of Object.entries(merged)) if (value) next.set(name, value);
1480 const query = next.toString();
1481 return query ? `/notifications?${query}` : "/notifications";
1482 };
1483 const views = [
1484 { view: "inbox", label: "Everything", icon: <Bell size={15} />, count: counts?.unread },
1485 { view: "saved", label: "Saved", icon: <Bookmark size={15} /> },
1486 { view: "done", label: "Done", icon: <Check size={15} /> },
1487 ] as const;
1488 return (
1489 <div className="flex h-full flex-col">
1490 <ModeHeader title="Notifications" />
1491 <nav aria-label="Notifications" className={PANEL}>
1492 <NavRows>
1493 {views.map((entry) => (
1494 <SidebarLink
1495 key={entry.view}
1496 to={address({ view: entry.view === "inbox" ? null : entry.view, before: null })}
1497 icon={entry.icon}
1498 count={"count" in entry ? (entry.count ?? undefined) : undefined}
1499 current={view === entry.view}
1500 >
1501 {entry.label}
1502 </SidebarLink>
1503 ))}
1504 </NavRows>
1505 <Rule />
1506 <NavGroup title="Why you were told">
1507 {REASON_FILTERS.map((entry) => (
1508 <SidebarLink
1509 key={entry.reason ?? "any"}
1510 to={address({ reason: entry.reason, before: null })}
1511 icon={<span className="block size-3.75" />}
1512 current={reason === entry.reason}
1513 >
1514 {entry.reason == null ? "Any reason" : entry.label}
1515 </SidebarLink>
1516 ))}
1517 </NavGroup>
1518 </nav>
1519 </div>
1520 );
1521}
1522
1523/** Your own settings, beside the page: under the account menu, not any workspace's. */
1524export function AccountSidebar({ username }: { username: string }) {
1525 return (
1526 <div className="flex h-full flex-col">
1527 <ModeHeader title="Your account" />
1528 <div className="min-h-0 grow">
1529 <AccountSettingsMenu username={username} />
1530 </div>
1531 </div>
1532 );
1533}
1534
1535/** Words for the sections a path can end in. */
1536const SECTIONS: Record<string, string> = {
1537 issues: "Issues",
1538 milestones: "Milestones",
1539 labels: "Labels",
1540 pulls: "Pull requests",
1541 queue: "Merge queue",
1542 commits: "Commits",
1543 actions: "Workflows",
1544 soon: "Soon",
1545 deployments: "Deployments",
1546 repository: "Repository",
1547 access: "Access",
1548 invitations: "Invitation",
1549 repositories: "Repositories",
1550 branches: "Branches",
1551 tags: "Tags",
1552 compare: "Compare",
1553 code: "Files",
1554 secrets: "Secrets and variables",
1555 settings: "Settings",
1556 people: "People",
1557 members: "Members",
1558 permissions: "Permissions",
1559 projects: "Projects",
1560 teams: "Teams",
1561 tokens: "Access tokens",
1562 "personal-access-tokens": "Personal access tokens",
1563 usage: "Usage",
1564 billing: "Billing and plans",
1565 integrations: "Integrations",
1566 ai: "AI",
1567 webhooks: "Webhooks",
1568 emoji: "Emoji",
1569 domains: "Domains",
1570 guardrails: "Guardrails",
1571 rules: "Rules",
1572 audit: "Audit log",
1573 tree: "Files",
1574 blob: "Files",
1575 security: "Security",
1576 packages: "Packages",
1577 runners: "Runners",
1578 environments: "Environments",
1579 workflows: "Workflows",
1580 observability: "Observability",
1581 insights: "Insights",
1582 sessions: "Sessions",
1583 work: "Work",
1584 chat: "Chat",
1585 artifacts: "Artifacts",
1586 home: "Home",
1587 apps: "Apps",
1588 "code-access": "Code access",
1589 overview: "Overview",
1590 workspace: "Workspace",
1591};
1592
1593/** Settings pages whose name differs from the section's of the same word. */
1594const SETTINGS_SECTIONS: Record<string, string> = { branches: "Branches and merging", actions: "Actions" };
1595
1596/** Where the page is, as a trail of links: workspace / repository / section. */
1597function Breadcrumbs({
1598 pathname,
1599 missing,
1600 repo,
1601 workspace,
1602}: {
1603 pathname: string;
1604 missing?: boolean;
1605 repo?: ShellData["repo"];
1606 /** The workspace you are in: the switcher names it, so the trail starts after it. */
1607 workspace: string | null;
1608}) {
1609 // A 404 names nothing from the address, unless the project is real and
1610 // visible and only something inside it is missing.
1611 const visibleRepo = /^\/([^/]+)\/([^/-][^/]*)(\/|$)/.exec(pathname);
1612 if (missing && !(visibleRepo && sameRepo(repo ?? null, { namespace: visibleRepo[1]!, name: visibleRepo[2]! }))) {
1613 return <Here>Not found</Here>;
1614 }
1615 const parts = pathname.split("/").filter(Boolean);
1616 const reserved = ["settings", "explore", "new", "search", "workspaces", "policies", "security", "support", "status", "invite", "notifications"];
1617 if (parts.length === 0) return <Here>Home</Here>;
1618 // Your settings: Settings / Emails.
1619 if (parts[0] === "settings") {
1620 const page = accountSettingsPage(pathname);
1621 return <Trail trail={[{ label: "Settings", to: FIRST_SETTINGS_PAGE }, ...(page ? [{ label: ACCOUNT_SETTINGS[page].title, to: `/settings/${page}` }] : [])]} />;
1622 }
1623 if (reserved.includes(parts[0]!)) {
1624 const words: Record<string, string> = {
1625 settings: "Account",
1626 explore: "Explore",
1627 new: "New project",
1628 search: "Search",
1629 workspaces: "New workspace",
1630 policies: "Policies",
1631 security: "Security",
1632 support: "Support",
1633 status: "Status",
1634 invite: "Invite",
1635 notifications: "Notifications",
1636 };
1637 return <Here>{words[parts[0]!]}</Here>;
1638 }
1639 // A person's profile, by their handle.
1640 if (parts[0] === "u" && parts[1]) return <ProfileCrumb username={parts[1]} />;
1641 const [owner, second, third, fourth] = parts;
1642 const ours = workspace != null && owner!.toLowerCase() === workspace.toLowerCase();
1643 const trail: Crumb[] = ours ? [] : [{ label: owner!, to: `/${owner}`, mono: true }];
1644 if (second === "-") {
1645 const page = `/${owner}/-/${third}`;
1646 if (third === "settings" && fourth === "chat") {
1647 // Chat settings is a page of its own, not one of General's.
1648 trail.push({ label: "Chat settings", to: `${page}/chat` });
1649 } else if (third) {
1650 // The workspace's settings pages each stand alone: General, Members, Permissions.
1651 trail.push({ label: third === "settings" ? "General" : (SECTIONS[third] ?? third), to: page });
1652 // Members names its invitations.
1653 const tabs: Record<string, string> = third === "members" ? { invitations: "Invitations" } : {};
1654 const tab = fourth ? tabs[fourth] : undefined;
1655 if (tab) trail.push({ label: tab, to: `${page}/${fourth}` });
1656 }
1657 } else if (second) {
1658 const repo = `/${owner}/${second}`;
1659 trail.push({ label: second, to: repo, mono: true });
1660 if (third === "pull" && fourth) trail.push({ label: `Pull request #${fourth}`, short: `#${fourth}`, to: `${repo}/pull/${fourth}` });
1661 else if (third === "issues" && fourth && fourth !== "new") trail.push({ label: `Issue #${fourth}`, short: `#${fourth}`, to: `${repo}/issues/${fourth}` });
1662 else if (third === "commit" && fourth) trail.push({ label: fourth.slice(0, 7), to: `${repo}/commit/${fourth}`, mono: true });
1663 // A Soon page names what is coming.
1664 else if (third === "soon" && fourth && roadmapItem(fourth)) trail.push({ label: roadmapItem(fourth)!.title, to: `${repo}/soon/${fourth}` });
1665 else if (third && SECTIONS[third]) {
1666 trail.push({ label: SECTIONS[third]!, to: `${repo}/${third}` });
1667 // A settings page names which one: Settings / Secrets and variables.
1668 if (third === "settings" && fourth && SECTIONS[fourth]) {
1669 trail.push({ label: SETTINGS_SECTIONS[fourth] ?? SECTIONS[fourth]!, to: `${repo}/settings/${fourth}` });
1670 }
1671 }
1672 }
1673 if (trail.length === 0) trail.push({ label: "Overview", to: `/${owner}` });
1674 return <Trail trail={trail} />;
1675}
1676
1677/** A profile's place in the top bar: the person's avatar and @handle, from the page once it has loaded. */
1678function ProfileCrumb({ username }: { username: string }) {
1679 const page = useRouteLoaderData("routes/user") as { profile?: { username: string; displayUsername?: string | null; avatar: string | null } } | undefined;
1680 const profile = page?.profile?.username.toLowerCase() === username.toLowerCase() ? page.profile : null;
1681 return (
1682 <Breadcrumb className="min-w-0">
1683 <BreadcrumbList>
1684 <BreadcrumbItem>
1685 <BreadcrumbPage asChild className="flex items-center gap-2 hover:bg-raised">
1686 <Link to={`/u/${profile?.username ?? username}`}>
1687 <Avatar name={profile?.username ?? username} image={profile?.avatar ?? null} size={20} />
1688 <span className="truncate font-mono text-[0.8125rem]">@{profile ? shownUsername(profile) : username}</span>
1689 </Link>
1690 </BreadcrumbPage>
1691 </BreadcrumbItem>
1692 </BreadcrumbList>
1693 </Breadcrumb>
1694 );
1695}
1696
1697/** A page with no trail to it, such as Today or Search: its name alone. */
1698function Here({ children }: { children: ReactNode }) {
1699 return (
1700 <Breadcrumb className="min-w-0">
1701 <BreadcrumbList>
1702 <BreadcrumbItem>
1703 <BreadcrumbPage>{children}</BreadcrumbPage>
1704 </BreadcrumbItem>
1705 </BreadcrumbList>
1706 </Breadcrumb>
1707 );
1708}
1709
1710/** One link of the trail; `short` is what a phone shows when it is the page itself. */
1711type Crumb = { label: string; to: string; mono?: boolean; short?: string };
1712
1713/**
1714 * The trail of links. On a phone there is room for one: the page itself,
1715 * with a way back to where it sits; the whole trail from a wider screen up.
1716 */
1717function Trail({ trail }: { trail: Crumb[] }) {
1718 // Up on a phone, unless up is the workspace itself: its pages are the tabs.
1719 const up = trail.length > 1 && !/^\/[^/]+$/.test(trail[trail.length - 2]!.to) ? trail[trail.length - 2]! : null;
1720 return (
1721 <Breadcrumb className="flex min-w-0 items-center">
1722 {up && (
1723 <Button asChild variant="ghost" size="icon-bar" className="-ml-1 sm:hidden">
1724 <Link to={up.to} prefetch="intent" aria-label={`Back to ${up.label}`}>
1725 <ChevronLeft size={16} />
1726 </Link>
1727 </Button>
1728 )}
1729 <BreadcrumbList>
1730 {trail.map((crumb, index) => {
1731 const last = index === trail.length - 1;
1732 const label =
1733 last && crumb.short ? (
1734 <>
1735 <span className="sm:hidden">{crumb.short}</span>
1736 <span className="hidden sm:inline">{crumb.label}</span>
1737 </>
1738 ) : (
1739 crumb.label
1740 );
1741 const mono = crumb.mono ? "font-mono text-[0.8125rem]" : "";
1742 return (
1743 <Fragment key={index}>
1744 {index > 0 && <BreadcrumbSeparator className="max-sm:hidden" />}
1745 <BreadcrumbItem className={last ? "" : "max-sm:hidden"}>
1746 {last ? (
1747 // The page you are on is still a link: to its own top, as the trail always was.
1748 <BreadcrumbPage asChild className={`hover:bg-raised ${mono}`}>
1749 <Link to={crumb.to} prefetch="intent">
1750 {label}
1751 </Link>
1752 </BreadcrumbPage>
1753 ) : (
1754 <BreadcrumbLink asChild className={mono}>
1755 <Link to={crumb.to} prefetch="intent">
1756 {label}
1757 </Link>
1758 </BreadcrumbLink>
1759 )}
1760 </BreadcrumbItem>
1761 </Fragment>
1762 );
1763 })}
1764 </BreadcrumbList>
1765 </Breadcrumb>
1766 );
1767}
1768
1769type Command = PaletteCommand;
1770
1771/** Everything the palette can jump to, from what the sidebar already knows. */
1772function commandsFor(user: User, shell: ShellData): Command[] {
1773 const ws = shell.workspace;
1774 const commands: Command[] = [
1775 ...(ws
1776 ? [
1777 { label: "Home", to: homePagePath(ws.slug), icon: <House size={15} /> },
1778 { label: "Chat", to: `/${ws.slug}/-/chat`, icon: <MessagesSquare size={15} /> },
1779 ...(hasCodeAccess(ws) ? [{ label: "Code overview", to: `/${ws.slug}/-/overview`, icon: <Code2 size={15} /> }] : []),
1780 { label: "Artifacts", to: `/${ws.slug}/-/artifacts`, icon: <Shapes size={15} /> },
1781 { label: "Apps", hint: "Everything installed that you can use", to: `/${ws.slug}/-/apps`, icon: <LayoutGrid size={15} /> },
1782 { label: "Workspace", hint: "Billing, policies, settings", to: `/${ws.slug}/-/workspace`, icon: <Building2 size={15} /> },
1783 ]
1784 : []),
1785 { label: "Explore repositories", to: "/explore", icon: <Compass size={15} /> },
1786 { label: "Search g1t", hint: "Repositories, code, issues, people", to: "/search", icon: <Search size={15} /> },
1787 { label: "Notifications", hint: "What needs you", to: "/notifications", icon: <Bell size={15} /> },
1788 { label: "New project", to: "/new", icon: <Plus size={15} /> },
1789 { label: "Your settings", to: FIRST_SETTINGS_PAGE, icon: <Settings size={15} /> },
1790 ...(Object.keys(ACCOUNT_SETTINGS) as AccountSettingsPage[])
1791 .filter((page) => page !== "profile")
1792 .map((page) => ({ label: ACCOUNT_SETTINGS[page].title, hint: "Your settings", to: `/settings/${page}`, icon: <Settings size={15} /> })),
1793 ...THEME_COMMANDS,
1794 ];
1795 const repo = shell.repo;
1796 if (repo) {
1797 const base = `/${repo.namespace}/${repo.name}`;
1798 const name = `${repo.namespace}/${repo.name}`;
1799 commands.unshift(
1800 { label: "Overview", hint: name, to: base, icon: <LayoutGrid size={15} /> },
1801 { label: "Code", hint: name, to: `${base}/code`, icon: <Code2 size={15} /> },
1802 { label: "Issues", hint: name, to: `${base}/issues`, icon: <CircleDot size={15} /> },
1803 { label: "New issue", hint: name, to: `${base}/issues/new`, icon: <Plus size={15} /> },
1804 { label: "Pull requests", hint: name, to: `${base}/pulls`, icon: <GitPullRequest size={15} /> },
1805 { label: "Commits", hint: name, to: `${base}/commits`, icon: <History size={15} /> },
1806 ...(repo.member
1807 ? [
1808 { label: "Deployments", hint: name, to: `${base}/deployments`, icon: <Rocket size={15} /> },
1809 { label: "Secrets and variables", hint: name, to: `${base}/settings/secrets`, icon: <Lock size={15} /> },
1810 { label: "Project settings", hint: name, to: `${base}/settings`, icon: <Settings size={15} /> },
1811 { label: "Repository settings", hint: name, to: `${base}/settings/repository`, icon: <Settings size={15} /> },
1812 ]
1813 : []),
1814 );
1815 }
1816 for (const membership of user.workspaces ?? []) {
1817 commands.push(
1818 { label: displayName(membership), hint: `Workspace · ${membership.slug}`, to: `/${membership.slug}`, icon: <Avatar name={membership.slug} image={membership.avatar} size={15} square /> },
1819 { label: "All projects", hint: membership.slug, to: `/${membership.slug}/-/projects`, icon: <LayoutGrid size={15} /> },
1820 { label: "People", hint: membership.slug, to: `/${membership.slug}/-/people`, icon: <Users size={15} /> },
1821 { label: "Usage", hint: membership.slug, to: `/${membership.slug}/-/usage`, icon: <BarChart3 size={15} /> },
1822 { label: "Billing and plans", hint: `${membership.slug} · Settings`, to: `/${membership.slug}/-/billing`, icon: <CreditCard size={15} /> },
1823 { label: "Access tokens", hint: `${membership.slug} · Settings`, to: `/${membership.slug}/-/tokens`, icon: <KeyRound size={15} /> },
1824 { label: "Integrations", hint: membership.slug, to: `/${membership.slug}/-/integrations`, icon: <Plug size={15} /> },
1825 { label: "AI models", hint: `${membership.slug} · Settings`, to: `/${membership.slug}/-/ai`, icon: <Sparkles size={15} /> },
1826 { label: "Members", hint: `${membership.slug} · Access`, to: `/${membership.slug}/-/members`, icon: <Users size={15} /> },
1827 ...(membership.role === "owner"
1828 ? [
1829 { label: "Getting started", hint: `${membership.slug} · Set up the workspace`, to: setupPath(membership.slug), icon: <Rocket size={15} /> },
1830 { label: "Invitations", hint: `${membership.slug} · Access`, to: `/${membership.slug}/-/members/invitations`, icon: <Mail size={15} /> },
1831 { label: "Permissions", hint: `${membership.slug} · Access`, to: `/${membership.slug}/-/permissions`, icon: <ShieldCheck size={15} /> },
1832 ]
1833 : []),
1834 );
1835 }
1836 for (const listed of shell.repos) {
1837 commands.push({
1838 label: listed.title ?? listed.name,
1839 hint: `${listed.namespace} · Project`,
1840 to: `/${listed.namespace}/${listed.name}`,
1841 icon: <Box size={15} />,
1842 });
1843 }
1844 return commands;
1845}
1846
1847/**
1848 * The page while the next one loads: after a moment it dims, under the
1849 * bar below, so it is plainly on its way out rather than frozen, and the
1850 * next page fades up from there. Sending a form does not dim it: the
1851 * form's button says it is working. Spread on the element holding the page.
1852 */
1853export function useLeaving() {
1854 const navigation = useNavigation();
1855 const method = navigation.formMethod?.toUpperCase();
1856 const leaving = navigation.state === "loading" && (method == null || method === "GET");
1857 return {
1858 "aria-busy": leaving || undefined,
1859 className: `transition-opacity motion-reduce:transition-none ${leaving ? "opacity-60 delay-200 duration-300" : "duration-150"}`,
1860 };
1861}
1862
1863/**
1864 * A bar across the top of the page while the next one loads, as GitHub
1865 * has: it appears at once, creeps towards the end while waiting, then fills
1866 * and fades when the page arrives.
1867 */
1868export function Progress() {
1869 const navigation = useNavigation();
1870 const busy = navigation.state !== "idle";
1871 const [width, setWidth] = useState(0);
1872 const [visible, setVisible] = useState(false);
1873 useEffect(() => {
1874 if (busy) {
1875 setVisible(true);
1876 setWidth(12);
1877 // Slows as it goes, never quite arriving until the page does.
1878 const timer = setInterval(() => setWidth((now) => now + (90 - now) * 0.12), 200);
1879 return () => clearInterval(timer);
1880 }
1881 setWidth((now) => (now > 0 ? 100 : 0));
1882 const fade = setTimeout(() => setVisible(false), 250);
1883 const reset = setTimeout(() => setWidth(0), 550);
1884 return () => {
1885 clearTimeout(fade);
1886 clearTimeout(reset);
1887 };
1888 }, [busy]);
1889 return (
1890 <div
1891 aria-hidden="true"
1892 className={`pointer-events-none fixed inset-x-0 top-0 z-60 h-0.75 transition-opacity duration-300 ${
1893 visible ? "opacity-100" : "opacity-0"
1894 }`}
1895 >
1896 <div
1897 className="h-full bg-accent shadow-[0_0_10px_var(--color-accent)] transition-[width] duration-200 ease-out"
1898 style={{ width: `${width}%` }}
1899 />
1900 </div>
1901 );
1902}
1903
1904/**
1905 * Which sidebar sits beside the page: each mode's own, or none. Home and
1906 * Apps are pages at full width, and so are g1t's own pages, such as its
1907 * policies, which are no workspace's. g1t beyond your workspaces (Explore,
1908 * a profile, another workspace's projects) has Explore's. Without a
1909 * workspace, only your own settings and Notifications have one.
1910 */
1911function sidebarFor(mode: ModeKey, workspace: boolean): Panel | null {
1912 if (!workspace) return mode === "account" || mode === "notifications" ? mode : null;
1913 if (mode === "home" || mode === "apps" || mode === "site") return null;
1914 return mode;
1915}
1916
1917/** The sidebars that sit beside the page, one per mode that has one. */
1918type Panel = "chat" | "artifacts" | "code" | "notifications" | "people" | "workspace" | "account" | "browse";
1919
1920/** Each sidebar's name, for the button that opens it on a phone. */
1921const MODE_MENU: Record<Panel, string> = {
1922 browse: "Explore",
1923 chat: "Chat",
1924 artifacts: "Artifacts",
1925 code: "Code",
1926 notifications: "Notifications",
1927 people: "People",
1928 workspace: "Workspace",
1929 account: "Your account",
1930};
1931
1932/** Whether a key press happened in something you type into, where Ctrl B is the editor's. */
1933function typing(target: EventTarget | null): boolean {
1934 if (!(target instanceof HTMLElement)) return false;
1935 return target.isContentEditable || target.closest("input, textarea, select, [contenteditable=''], [contenteditable='true'], [role='textbox']") != null;
1936}
1937
1938/** Ctrl B (⌘B on a Mac) shows or hides the sidebar, except while typing. */
1939function useSidebarShortcut(toggle: () => void) {
1940 useEffect(() => {
1941 const onKey = (event: KeyboardEvent) => {
1942 if (event.key.toLowerCase() !== "b" || event.altKey || event.shiftKey || !(event.ctrlKey || event.metaKey)) return;
1943 if (event.defaultPrevented || typing(event.target)) return;
1944 event.preventDefault();
1945 toggle();
1946 };
1947 window.addEventListener("keydown", onKey);
1948 return () => window.removeEventListener("keydown", onKey);
1949 }, [toggle]);
1950}
1951
1952/**
1953 * Search or jump to: the command palette. On a computer it looks like the
1954 * field it opens, with its shortcut; on a phone, a magnifier.
1955 */
1956function SearchButton({ onClick, place }: { onClick: () => void; place: "bar" | "sidebar" }) {
1957 const field = (
1958 <Button
1959 variant="outline"
1960 size="sm"
1961 aria-label="Search or jump to"
1962 onClick={onClick}
1963 className={
1964 place === "sidebar"
1965 ? "w-full justify-start bg-bg font-normal text-faint hover:bg-bg hover:text-muted"
1966 : "mr-1 w-[min(18rem,26vw)] justify-start bg-surface font-normal text-faint hover:bg-surface hover:text-muted max-md:hidden"
1967 }
1968 >
1969 <Search size={15} />
1970 <span className="grow truncate text-left">Search or jump to</span>
1971 <PaletteKey className="px-1.5 text-[0.625rem] leading-4 text-muted" />
1972 </Button>
1973 );
1974 if (place === "sidebar") return field;
1975 return (
1976 <>
1977 <Button variant="ghost" size="icon-bar" aria-label="Search or jump to" onClick={onClick} className="md:hidden">
1978 <Search size={18} />
1979 </Button>
1980 {field}
1981 </>
1982 );
1983}
1984
1985/** The sidebar's shortcut, for the hint on its toggle. */
1986function useSidebarKey(): string {
1987 return sidebarKeyLabel(typeof navigator === "undefined" ? null : navigator.platform);
1988}
1989
1990/**
1991 * The app: three surfaces that never blur together. The rail, a narrow
1992 * column of icons down the window's left edge; the mode's sidebar, flat
1993 * against it with a hairline between, which folds away with Ctrl B and is
1994 * a drawer below 1024px; and the page, flat against the sidebar and
1995 * filling the rest of the window, with its top bar across the top and a
1996 * line under it: the sidebar's toggle, where you are, search, Ask, the bell and
1997 * Create new. On a phone the rail is a bar along the bottom and the page
1998 * fills the window above it, flat as well. Only for someone signed in; without a workspace yet, there
1999 * is no rail. The rail and the sidebar are drawn from the sidebar kit
2000 * (components/ui/sidebar.tsx): one provider holds whether the sidebar is
2001 * open on a computer and whether the drawer is.
2002 */
2003export function AppShell({
2004 user,
2005 shell,
2006 missing = false,
2007 banner,
2008 sidebarClosed = false,
2009 children,
2010}: {
2011 user: User;
2012 shell: ShellData;
2013 /** The page is a 404 (see CodeSidebar). */
2014 missing?: boolean;
2015 banner?: ReactNode;
2016 /** Whether the person folded the sidebar away, as their cookie says. */
2017 sidebarClosed?: boolean;
2018 children: ReactNode;
2019}) {
2020 const { pathname } = useLocation();
2021 const [drawer, setDrawer] = useState(false);
2022 const [closed, setClosed] = useState(sidebarClosed);
2023 const [palette, setPalette] = useState(false);
2024 const commands = useMemo(() => commandsFor(user, shell), [user, shell]);
2025
2026 // A new page closes the drawer.
2027 useEffect(() => setDrawer(false), [pathname]);
2028 usePaletteShortcut(() => setPalette((open) => !open));
2029 // In the desktop app, search is in the middle of its title bar, as in Slack, and not in the top bar too.
2030 const titleSearch = useTitleBarSearch(`Search ${shell.workspace?.name ?? shell.workspace?.slug ?? "g1t"}`, () => setPalette(true));
2031 const leaving = useLeaving();
2032 useVisualViewport();
2033 const going = useNavigation().location?.pathname;
2034 const ws = shell.workspace;
2035 // Beyond your workspaces (Explore, a profile, another workspace's
2036 // projects), the shell is Explore's; anything of yours is its mode's.
2037 const browsing = browsingOf(going ?? pathname, {
2038 slug: ws?.slug ?? null,
2039 memberships: (user.workspaces ?? []).map((membership) => membership.slug),
2040 shared: shell.shared,
2041 username: user.username,
2042 });
2043 const mode: ModeKey = browsing ? "browse" : modeOf(going ?? pathname, ws?.slug ?? null);
2044 const panel = sidebarFor(mode, ws != null);
2045 const { sidebar: chatSidebar } = useChatSidebar();
2046 // Notify: the feed socket's live counts (lib/notify-client.ts) once it has them; the page's until then.
2047 const live = useLiveBadges(ws?.slug);
2048 const chatUnread = chatSidebar
2049 ? unreadTotals(chatSidebar.entries)
2050 : live?.chat != null
2051 ? { unread: live.chat, mentions: live.mentions ?? 0 }
2052 : (shell.chat ?? { unread: 0, mentions: 0 });
2053 const notificationsUnread = live?.inbox ?? shell.inbox?.unread ?? 0;
2054 const unread = { notifications: notificationsUnread, chat: chatUnread.unread, mentions: chatUnread.mentions };
2055
2056 // Folding the sidebar away on a computer is remembered, so the next page is drawn the same from the server.
2057 const toggleSidebar = useCallback(() => {
2058 if (!window.matchMedia("(min-width: 1024px)").matches) {
2059 setDrawer((open) => !open);
2060 return;
2061 }
2062 setClosed((was) => {
2063 document.cookie = sidebarCookie(!was, window.location.protocol === "https:");
2064 return !was;
2065 });
2066 }, []);
2067 useSidebarShortcut(useCallback(() => {
2068 if (panel) toggleSidebar();
2069 }, [panel, toggleSidebar]));
2070
2071 const inline = panel != null && !closed;
2072 const sidebarNode = () => {
2073 if (!panel) return null;
2074 if (!ws) return panel === "notifications" ? <NotificationsSidebar counts={shell.inbox ?? null} /> : <AccountSidebar username={user.username} />;
2075 switch (panel) {
2076 case "code":
2077 return <CodeSidebar user={user} shell={shell} missing={missing} />;
2078 case "browse":
2079 return <CodeSidebar user={user} shell={shell} missing={missing} browsing={browsing} />;
2080 case "chat":
2081 return <ChatSidebar slug={ws.slug} />;
2082 case "artifacts":
2083 return <FoliosSidebar slug={ws.slug} />;
2084 case "notifications":
2085 return <NotificationsSidebar counts={shell.inbox ?? null} />;
2086 case "people":
2087 return <PeopleSidebar slug={ws.slug} />;
2088 case "workspace":
2089 return <WorkspaceSidebar slug={ws.slug} owner={ws.role === "owner"} />;
2090 case "account":
2091 return <AccountSidebar username={user.username} />;
2092 }
2093 };
2094 const sidebarKey = useSidebarKey();
2095 // Search or jump to sits at the top of the sidebar, except in Chat and
2096 // Artifacts, whose sidebars search their own lists: there it stays in the bar.
2097 const sidebarSearch = panel != null && panel !== "chat" && panel !== "artifacts";
2098 // The sidebar's head: the workspace and its switcher, the way to fold the
2099 // sidebar or close the drawer, and search, which opens the palette.
2100 const sidebarTop = (inDrawer: boolean) => (
2101 <SidebarHeader className="gap-1 px-2 pt-0 pb-2">
2102 <div className="flex h-14 shrink-0 items-center gap-1">
2103 {ws ? (
2104 <WorkspaceSwitcher user={user} workspace={ws} />
2105 ) : (
2106 <Link to="/" aria-label="g1t" className="mr-auto flex h-9 items-center rounded-md px-2">
2107 <Logo className="text-[1.125rem]" />
2108 </Link>
2109 )}
2110 {inDrawer ? (
2111 <Button type="button" aria-label="Close menu" onClick={() => setDrawer(false)} variant="ghost" size="icon-sm" className="text-faint">
2112 <X size={16} />
2113 </Button>
2114 ) : (
2115 <SidebarTrigger hint={`Hide the sidebar (${sidebarKey})`} className="text-faint" />
2116 )}
2117 </div>
2118 {sidebarSearch && <SearchButton place="sidebar" onClick={() => setPalette(true)} />}
2119 </SidebarHeader>
2120 );
2121
2122 // On a phone (below 768px): the bottom bar, and a conversation full screen.
2123 const conversation = isConversation(going ?? pathname);
2124 // Where the page panel starts: 8px past the rail (56px), or 8px past the sidebar (56 + 240px) when it is open.
2125 // The page starts where the rail (3.5rem) and, open, the sidebar (15rem) end.
2126 const pad = ws ? (inline ? "md:pl-14 lg:pl-74" : "md:pl-14") : inline ? "lg:pl-60" : "";
2127
2128 return (
2129 <SidebarProvider open={!closed} onOpenChange={(open) => setClosed(!open)} openMobile={drawer} onOpenMobileChange={setDrawer} toggleSidebar={toggleSidebar}>
2130 <Progress />
2131 {ws && (
2132 <div className="fixed top-(--frame-top) bottom-0 left-0 z-40 hidden md:block">
2133 <Rail workspace={ws} mode={mode} pins={shell.pins ?? []} unread={unread} account={<AccountMenu user={user} />} />
2134 </div>
2135 )}
2136 {panel && (
2137 <Sidebar
2138 role="complementary"
2139 aria-label={`${MODE_MENU[panel]} sidebar`}
2140 className={`fixed top-(--frame-top) bottom-0 z-40 max-lg:hidden ${ws ? "left-14" : "left-0"}`}
2141 >
2142 {sidebarTop(false)}
2143 <div className="min-h-0 grow">{sidebarNode()}</div>
2144 </Sidebar>
2145 )}
2146 {/* The drawer is a sheet: a dialog that holds focus, closes on Escape or
2147 a tap outside, and gives focus back to the button that opened it. */}
2148 {panel && (
2149 <SidebarMobile title={`${MODE_MENU[panel]} menu`} className="pb-[env(safe-area-inset-bottom)] max-md:[&_nav_a]:min-h-10">
2150 {sidebarTop(true)}
2151 <div className="min-h-0 grow">{sidebarNode()}</div>
2152 </SidebarMobile>
2153 )}
2154
2155 <div className={`min-h-dvh pt-(--frame-top) pb-(--tabbar-h) ${pad}`}>
2156 {/* The top bar always has its line, so a page's own header (data-page-head: a conversation's, a project's,
2157 a sticky one under an open artifact) sits under it as its own band. */}
2158 <div className="flex min-h-[calc(100dvh-var(--frame-top)-var(--tabbar-h))] min-w-0 flex-col bg-bg">
2159 <header
2160 className={`sticky top-(--frame-top) z-30 flex h-14 items-center gap-1 border-b border-line bg-bg pr-2 pl-2 sm:pr-3 ${inline ? "lg:pl-3.5" : ""} ${conversation ? "max-md:hidden" : ""}`}
2161 >
2162 {panel && (
2163 <SidebarTrigger
2164 hint={`Show the sidebar (${sidebarKey})`}
2165 aria-label={drawer ? "Hide the sidebar" : "Show the sidebar"}
2166 aria-expanded={drawer}
2167 className={`max-md:size-11 ${inline ? "lg:hidden" : ""}`}
2168 />
2169 )}
2170 {ws && (
2171 <span className={`flex min-w-0 shrink items-center gap-1.5 ${inline ? "lg:hidden" : ""}`}>
2172 <WorkspaceSwitcher user={user} workspace={ws} compact />
2173 <span aria-hidden="true" className="text-line-strong">
2174 /
2175 </span>
2176 </span>
2177 )}
2178 <Breadcrumbs pathname={pathname} missing={missing} repo={shell.repo} workspace={ws?.slug ?? null} />
2179 {/* Search, Ask, then the bell and Create new: one height, one rhythm. */}
2180 <div className="ml-auto flex shrink-0 items-center gap-1 md:gap-1.5">
2181 {/* With the sidebar open, search is at its top. */}
2182 {!titleSearch && (
2183 <span className={`flex ${inline && sidebarSearch ? "lg:hidden" : ""}`}>
2184 <SearchButton place="bar" onClick={() => setPalette(true)} />
2185 </span>
2186 )}
2187 {ws && <AskButton key={ws.slug} slug={ws.slug} />}
2188 <Separator orientation="vertical" className="mx-1 data-[orientation=vertical]:h-5 max-md:hidden" />
2189 {/* On a phone, Notifications is in the bottom bar. */}
2190 <span className="flex max-md:hidden">
2191 <NotificationsBell counts={shell.inbox ? { ...shell.inbox, unread: notificationsUnread } : null} />
2192 </span>
2193 <CreateMenu shell={shell} />
2194 {/* Without a workspace there is no rail: the account is here. */}
2195 {!ws && <AccountMenu user={user} side="bottom" />}
2196 </div>
2197 </header>
2198 {banner}
2199 <main id="content" tabIndex={-1} {...leaving} className={`min-w-0 grow outline-none ${leaving.className}`}>
2200 <InMain.Provider value={true}>{children}</InMain.Provider>
2201 </main>
2202 </div>
2203 </div>
2204 {ws && <BottomBar user={user} workspace={ws} mode={mode} pins={shell.pins ?? []} unread={unread} onReselect={panel ? () => setDrawer(true) : undefined} />}
2205 <CommandPalette open={palette} onOpenChange={setPalette} commands={commands} repo={shell.repo ? `${shell.repo.namespace}/${shell.repo.name}` : null} />
2206 </SidebarProvider>
2207 );
2208}
2209
2210/** Create new: a project, an issue in the one you are in, a workspace or a team. */
2211function CreateMenu({ shell }: { shell: ShellData }) {
2212 return (
2213 <DropdownMenu>
2214 <Hint label="Create new">
2215 <DropdownMenuTrigger asChild>
2216 <Button variant="ghost" size="bar" aria-label="Create new" className="gap-0.5 px-1.5 text-fg/90">
2217 <Plus size={17} className="max-md:size-5" />
2218 <ChevronDown size={12} className="text-faint max-md:hidden" />
2219 </Button>
2220 </DropdownMenuTrigger>
2221 </Hint>
2222 <DropdownMenuContent align="end" className="min-w-52">
2223 {shell.repo && (
2224 <>
2225 <DropdownMenuLabel className="truncate">In {shell.repo.name}</DropdownMenuLabel>
2226 <DropdownMenuItem asChild>
2227 <Link to={`/${shell.repo.namespace}/${shell.repo.name}/issues/new`}>
2228 <CircleDot />
2229 New issue
2230 </Link>
2231 </DropdownMenuItem>
2232 <DropdownMenuSeparator />
2233 </>
2234 )}
2235 <DropdownMenuItem asChild>
2236 <Link to="/new">
2237 <Box />
2238 New project
2239 </Link>
2240 </DropdownMenuItem>
2241 <DropdownMenuItem asChild>
2242 <Link to="/new/github">
2243 <GitBranch />
2244 Import from GitHub
2245 </Link>
2246 </DropdownMenuItem>
2247 {/* A team in the workspace you are in, for whoever it lets create one. A new workspace is made from the workspace switcher in the rail. */}
2248 {shell.workspace && <DropdownMenuSeparator />}
2249 {shell.workspace &&
2250 (mayCreateTeams(shell.workspace.team_creation, shell.workspace.role) ? (
2251 <DropdownMenuItem asChild>
2252 <Link to={`/${shell.workspace.slug}/-/teams/new`}>
2253 <UsersRound />
2254 New team
2255 </Link>
2256 </DropdownMenuItem>
2257 ) : (
2258 <DropdownMenuItem disabled>
2259 <UsersRound />
2260 New team
2261 <span className="ml-auto pl-3 text-xs text-faint">Owners only</span>
2262 </DropdownMenuItem>
2263 ))}
2264 </DropdownMenuContent>
2265 </DropdownMenu>
2266 );
2267}