pr_01m47d15m3e54sn21z27rpy5n9/apps/web/app/lib/chrome.ts

99 lines3,069 bytesCodeBlame

Pick any line to see why it is the way it is: the commit, the pull request and issue it came from, and what the agent was thinking.

Team plan, an open-source pool, monthly trials and honest metering; the sidebar for everyone; a workspace that stays put1/**
2 * Which frame a page is drawn in, and what the sidebar offers someone who
3 * is not signed in.
4 *
5 * g1t is a sidebar site: projects, Explore, Search, profiles and
6 * not-found pages are drawn in the app's sidebar for everyone, so a
7 * visitor browsing public projects finds their way the same as a member.
8 * Only the front page and the pages about signing in or paying keep the
9 * marketing header and footer.
10 */
11
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look12import type { Abilities, Capability } from "@g1t/contracts";
13
Team plan, an open-source pool, monthly trials and honest metering; the sidebar for everyone; a workspace that stays put14/** Pages a visitor sees in the marketing frame. */
15const MARKETING = new Set([
16 "/",
17 "/pricing",
18 "/login",
19 "/register",
20 "/logout",
21 "/verify",
22 "/forgot",
23 "/reset",
24 "/device",
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look25 // Who makes g1t, and the promises it keeps: the policies, security,
26 // support and status.
27 "/policies",
28 "/security",
29 "/support",
30 "/status",
Team plan, an open-source pool, monthly trials and honest metering; the sidebar for everyone; a workspace that stays put31 // These send a visitor to sign in; the frame matters only for a moment.
32 "/new",
33 "/settings",
34 "/workspaces/new",
35]);
36
37/** Whether the page is drawn in the app's sidebar frame. */
38export function usesAppShell(pathname: string, signedIn: boolean): boolean {
39 if (signedIn) return true;
40 const path = pathname.length > 1 ? pathname.replace(/\/+$/, "") : pathname;
41 if (MARKETING.has(path)) return false;
42 if (path === "/oauth" || path.startsWith("/oauth/")) return false;
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look43 // An invite link is the front door: the marketing frame, like /register.
44 if (path.startsWith("/invite/")) return false;
45 if (path.startsWith("/policies/")) return false;
Team plan, an open-source pool, monthly trials and honest metering; the sidebar for everyone; a workspace that stays put46 return true;
47}
48
49export type SidebarItem = { label: string; to: string };
50
51/** The visitor's sidebar menu: where to browse from. */
52export const VISITOR_LINKS: SidebarItem[] = [
53 { label: "Explore", to: "/explore" },
54 { label: "Search", to: "/search" },
55];
56
57/** The project pages the sidebar lists, by key, for a member or not. */
58export type ProjectPage =
59 | "code"
60 | "issues"
61 | "pulls"
62 | "agents"
63 | "actions"
64 | "deployments"
65 | "observability"
66 | "security"
67 | "insights"
68 | "settings";
69
70/**
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look71 * What a page needs beyond a role on the repository, once what the viewer
72 * may do is known: Security's findings are for people who can push.
73 */
74export const PAGE_NEEDS: Partial<Record<ProjectPage, Capability>> = { security: "push" };
75
76/**
77 * A project's menu, in order. Security and Settings are for people with a
78 * role on its repository, and a page in `PAGE_NEEDS` only for those whose
79 * role has its capability (`can`, once the repository's page has loaded);
80 * everyone who can see the project sees the rest.
Team plan, an open-source pool, monthly trials and honest metering; the sidebar for everyone; a workspace that stays put81 */
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look82export function projectPages(member: boolean, can?: Partial<Abilities>): ProjectPage[] {
Team plan, an open-source pool, monthly trials and honest metering; the sidebar for everyone; a workspace that stays put83 const pages: (ProjectPage | false)[] = [
84 "code",
85 "issues",
86 "pulls",
87 "agents",
88 "actions",
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look89 // A public repository's deployments and build logs are for anyone, as its code is.
90 "deployments",
Team plan, an open-source pool, monthly trials and honest metering; the sidebar for everyone; a workspace that stays put91 "observability",
92 member && "security",
93 "insights",
94 member && "settings",
95 ];
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look96 return pages.filter(
97 (page): page is ProjectPage => page !== false && (!can || !PAGE_NEEDS[page] || Boolean(can[PAGE_NEEDS[page]!])),
98 );
Team plan, an open-source pool, monthly trials and honest metering; the sidebar for everyone; a workspace that stays put99}