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