pr_01m47d15m3e54sn21z27rpy5n9/apps/web/app/lib/chrome.ts
| 1 | /** |
| 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 | |
| 12 | /** Pages a visitor sees in the marketing frame. */ |
| 13 | const MARKETING = new Set([ |
| 14 | "/", |
| 15 | "/pricing", |
| 16 | "/login", |
| 17 | "/register", |
| 18 | "/logout", |
| 19 | "/verify", |
| 20 | "/forgot", |
| 21 | "/reset", |
| 22 | "/device", |
| 23 | // These send a visitor to sign in; the frame matters only for a moment. |
| 24 | "/new", |
| 25 | "/settings", |
| 26 | "/workspaces/new", |
| 27 | ]); |
| 28 | |
| 29 | /** Whether the page is drawn in the app's sidebar frame. */ |
| 30 | export function usesAppShell(pathname: string, signedIn: boolean): boolean { |
| 31 | if (signedIn) return true; |
| 32 | const path = pathname.length > 1 ? pathname.replace(/\/+$/, "") : pathname; |
| 33 | if (MARKETING.has(path)) return false; |
| 34 | if (path === "/oauth" || path.startsWith("/oauth/")) return false; |
| 35 | return true; |
| 36 | } |
| 37 | |
| 38 | export type SidebarItem = { label: string; to: string }; |
| 39 | |
| 40 | /** The visitor's sidebar menu: where to browse from. */ |
| 41 | export const VISITOR_LINKS: SidebarItem[] = [ |
| 42 | { label: "Explore", to: "/explore" }, |
| 43 | { label: "Search", to: "/search" }, |
| 44 | ]; |
| 45 | |
| 46 | /** The project pages the sidebar lists, by key, for a member or not. */ |
| 47 | export type ProjectPage = |
| 48 | | "code" |
| 49 | | "issues" |
| 50 | | "pulls" |
| 51 | | "agents" |
| 52 | | "actions" |
| 53 | | "deployments" |
| 54 | | "observability" |
| 55 | | "security" |
| 56 | | "insights" |
| 57 | | "settings"; |
| 58 | |
| 59 | /** |
| 60 | * A project's menu, in order. Deployments, Security and Settings are for |
| 61 | * members only; everyone who can see the project sees the rest. |
| 62 | */ |
| 63 | export function projectPages(member: boolean): ProjectPage[] { |
| 64 | const pages: (ProjectPage | false)[] = [ |
| 65 | "code", |
| 66 | "issues", |
| 67 | "pulls", |
| 68 | "agents", |
| 69 | "actions", |
| 70 | member && "deployments", |
| 71 | "observability", |
| 72 | member && "security", |
| 73 | "insights", |
| 74 | member && "settings", |
| 75 | ]; |
| 76 | return pages.filter((page): page is ProjectPage => page !== false); |
| 77 | } |