g1t/apps/web/app/routes/repo/layout.tsx
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.
| Projects: what a workspace builds and runs, first on every page | 1 | import { Box, CircleDot, Code2, GitPullRequest, History, LayoutGrid, ListTree, Lock, Rocket, Settings } from "lucide-react"; |
| A flat project menu with Code first, views as tabs, and Stripe for every owner | 2 | import { Link, NavLink, Outlet, data, useLocation, useRouteLoaderData } from "react-router"; |
| Projects: what a workspace builds and runs, first on every page | 3 | |
| 4 | import type { Project } from "@g1t/contracts"; | |
| Initial g1t: services, event bus, intents and attempts | 5 | |
| 6 | import type { Route } from "./+types/layout"; | |
| Social cards for every page: og.g1t.sh | 7 | import { page } from "../../lib/meta"; |
| A flat project menu with Code first, views as tabs, and Stripe for every owner | 8 | import { type Tab as PageTab, tabsFor } from "../../lib/project-nav"; |
| Agents as a team: lifecycle, merge queue, billing and a new shell | 9 | import { Pill, TabLink as Tab } from "../../components/ui"; |
| Agents and memory, checks and conflicts, profiles, slug renames, custom domains | 10 | import { redirectIfRenamed } from "../../lib/renamed.server"; |
| Projects: what a workspace builds and runs, first on every page | 11 | import { projects, repos, work } from "../../lib/services.server"; |
| Agents as a team: lifecycle, merge queue, billing and a new shell | 12 | import { getViewer, roleIn, unwrap } from "../../lib/session.server"; |
| Initial g1t: services, event bus, intents and attempts | 13 | |
| Social cards for every page: og.g1t.sh | 14 | export function meta({ loaderData: loaded, params, ...args }: Route.MetaArgs) { |
| 15 | return page(args, { title: `${loaded?.project?.name ?? params.repo} · ${params.owner} · g1t` }); | |
| Initial g1t: services, event bus, intents and attempts | 16 | } |
| 17 | ||
| Agents and memory, checks and conflicts, profiles, slug renames, custom domains | 18 | export async function loader({ params, context, request }: Route.LoaderArgs) { |
| Initial g1t: services, event bus, intents and attempts | 19 | const viewer = getViewer(context); |
| 20 | const path = { namespace: params.owner, name: params.repo }; | |
| Projects: what a workspace builds and runs, first on every page | 21 | const [repo, counts, found] = await Promise.all([ |
| Rust repos service with shipping; pull requests kept in the model | 22 | repos.get(path, viewer), |
| Issues and pull requests replace intents and attempts | 23 | work.counts(path, viewer), |
| Projects: what a workspace builds and runs, first on every page | 24 | projects.get(params.owner, params.repo, viewer), |
| Initial g1t: services, event bus, intents and attempts | 25 | ]); |
| Agents and memory, checks and conflicts, profiles, slug renames, custom domains | 26 | if (!repo.ok && !found.ok) { |
| 27 | // Under a workspace's old name, after a rename: the project is at the new one. | |
| 28 | await redirectIfRenamed(request, params.owner); | |
| 29 | throw data(null, { status: 404 }); | |
| 30 | } | |
| Projects: what a workspace builds and runs, first on every page | 31 | let project: Project | null = found.ok ? found.value : null; |
| 32 | // A repository made a moment ago, before its project: make it now. | |
| 33 | if (!project && repo.ok && !repo.value.forkOf) { | |
| 34 | const own = await projects.byRepo(repo.value.id); | |
| 35 | project = own.find((p) => p.slug === params.repo.toLowerCase()) ?? own[0] ?? null; | |
| 36 | } | |
| Initial g1t: services, event bus, intents and attempts | 37 | return { |
| 38 | repo: unwrap(repo), | |
| Projects: what a workspace builds and runs, first on every page | 39 | project, |
| Issues and pull requests replace intents and attempts | 40 | open: counts.ok ? counts.value : { issues: 0, pulls: 0 }, |
| Agents as a team: lifecycle, merge queue, billing and a new shell | 41 | member: roleIn(viewer, params.owner) != null, |
| Initial g1t: services, event bus, intents and attempts | 42 | }; |
| 43 | } | |
| 44 | ||
| Projects: what a workspace builds and runs, first on every page | 45 | /** The project the page is in, for the pages under it. */ |
| 46 | export function useProject() { | |
| 47 | return useRouteLoaderData<typeof loader>("routes/repo/layout"); | |
| 48 | } | |
| 49 | ||
| 50 | function Header({ project, isPrivate, namespace, name, description, large }: { | |
| 51 | project: Project | null; | |
| 52 | isPrivate: boolean; | |
| 53 | namespace: string; | |
| 54 | name: string; | |
| 55 | description: string | null; | |
| 56 | large?: boolean; | |
| 57 | }) { | |
| 58 | const base = `/${namespace}/${name}`; | |
| 59 | return ( | |
| 60 | <div className="flex flex-wrap items-center gap-x-3 gap-y-1"> | |
| 61 | <span | |
| 62 | className={`flex shrink-0 items-center justify-center rounded-md bg-raised text-muted ring-1 ring-line ${large ? "size-8" : "size-6"}`} | |
| 63 | > | |
| 64 | {isPrivate ? <Lock size={large ? 15 : 13} /> : <Box size={large ? 15 : 13} />} | |
| 65 | </span> | |
| 66 | <h1 className={large ? "text-lg" : "text-[0.9375rem]"}> | |
| 67 | <Link to={`/${namespace}`} className="font-mono text-muted hover:text-fg"> | |
| 68 | {namespace} | |
| 69 | </Link> | |
| 70 | <span className="mx-1.5 text-faint">/</span> | |
| 71 | <Link to={base} className="font-semibold hover:underline"> | |
| 72 | {project?.name ?? name} | |
| 73 | </Link> | |
| 74 | </h1> | |
| 75 | <Pill>{isPrivate ? "private" : "public"}</Pill> | |
| 76 | {description && <p className="min-w-0 truncate text-sm text-muted">{description}</p>} | |
| 77 | </div> | |
| 78 | ); | |
| 79 | } | |
| 80 | ||
| A flat project menu with Code first, views as tabs, and Stripe for every owner | 81 | /** |
| 82 | * The views of the page the project is on, as tabs across its top: Files, | |
| 83 | * Commits and what is coming under Code, and so on. Soon tabs open their | |
| 84 | * roadmap page, under the same tabs. | |
| 85 | */ | |
| 86 | function PageTabs({ base, tabs }: { base: string; tabs: PageTab[] }) { | |
| 87 | const { pathname } = useLocation(); | |
| 88 | const rest = pathname.slice(base.length + 1); | |
| 89 | const current = (tab: PageTab) => | |
| 90 | [tab.path, ...(tab.also ?? [])].some((path) => rest === path || rest.startsWith(`${path}/`)); | |
| 91 | return ( | |
| Observability gets its own page; tabs never overflow | 92 | <nav aria-label="Views" className="-mb-px flex gap-1 overflow-x-auto [scrollbar-width:none] [&::-webkit-scrollbar]:hidden"> |
| A flat project menu with Code first, views as tabs, and Stripe for every owner | 93 | {tabs.map((tab) => ( |
| 94 | <NavLink | |
| 95 | key={tab.path} | |
| 96 | to={`${base}/${tab.path}`} | |
| 97 | title={tab.about} | |
| 98 | prefetch="intent" | |
| 99 | className={`flex shrink-0 items-center gap-1.5 border-b-2 px-3 pt-1 pb-2.5 text-sm transition-colors ${ | |
| 100 | current(tab) | |
| 101 | ? "border-accent font-medium text-fg" | |
| 102 | : tab.soon | |
| 103 | ? "border-transparent text-faint hover:text-muted" | |
| 104 | : "border-transparent text-muted hover:text-fg" | |
| 105 | }`} | |
| 106 | > | |
| 107 | {tab.label} | |
| Observability gets its own page; tabs never overflow | 108 | {/* Soon, said quietly: a dot, with the word for screen readers. */} |
| A flat project menu with Code first, views as tabs, and Stripe for every owner | 109 | {tab.soon && ( |
| Observability gets its own page; tabs never overflow | 110 | <> |
| 111 | <span aria-hidden="true" className="size-1.5 rounded-full bg-accent/70" /> | |
| 112 | <span className="sr-only">(soon)</span> | |
| 113 | </> | |
| A flat project menu with Code first, views as tabs, and Stripe for every owner | 114 | )} |
| 115 | </NavLink> | |
| 116 | ))} | |
| 117 | </nav> | |
| 118 | ); | |
| 119 | } | |
| 120 | ||
| Projects: what a workspace builds and runs, first on every page | 121 | export default function ProjectLayout({ loaderData }: Route.ComponentProps) { |
| 122 | const { repo, project, open, member } = loaderData; | |
| Initial g1t: services, event bus, intents and attempts | 123 | const base = `/${repo.namespace}/${repo.name}`; |
| Agents as a team: lifecycle, merge queue, billing and a new shell | 124 | const signedIn = useRouteLoaderData("root")?.user != null; |
| Projects: what a workspace builds and runs, first on every page | 125 | const description = project?.description ?? repo.description; |
| A flat project menu with Code first, views as tabs, and Stripe for every owner | 126 | const { pathname } = useLocation(); |
| 127 | const tabs = tabsFor(pathname.slice(base.length + 1), member); | |
| Agents as a team: lifecycle, merge queue, billing and a new shell | 128 | if (signedIn) { |
| 129 | return ( | |
| 130 | <> | |
| 131 | <div className="border-b border-line"> | |
| A flat project menu with Code first, views as tabs, and Stripe for every owner | 132 | <div className={`mx-auto max-w-6xl px-4 sm:px-6 ${tabs ? "pt-3" : "py-3"}`}> |
| Projects: what a workspace builds and runs, first on every page | 133 | <Header |
| 134 | project={project} | |
| 135 | isPrivate={repo.isPrivate} | |
| 136 | namespace={repo.namespace} | |
| 137 | name={repo.name} | |
| 138 | description={description} | |
| 139 | /> | |
| A flat project menu with Code first, views as tabs, and Stripe for every owner | 140 | {tabs && ( |
| 141 | <div className="mt-3"> | |
| 142 | <PageTabs base={base} tabs={tabs} /> | |
| 143 | </div> | |
| 144 | )} | |
| Agents as a team: lifecycle, merge queue, billing and a new shell | 145 | </div> |
| 146 | </div> | |
| 147 | <div className="mx-auto max-w-6xl px-4 py-6 sm:px-6"> | |
| 148 | <Outlet /> | |
| 149 | </div> | |
| 150 | </> | |
| 151 | ); | |
| 152 | } | |
| Initial g1t: services, event bus, intents and attempts | 153 | return ( |
| API and MCP server, Rust identity service, registration, site redesign | 154 | <> |
| Projects: what a workspace builds and runs, first on every page | 155 | {/* The project's own header band, under the site header. */} |
| API and MCP server, Rust identity service, registration, site redesign | 156 | <div className="border-b border-line bg-surface/60"> |
| 157 | <div className="mx-auto max-w-6xl px-4 pt-6"> | |
| Projects: what a workspace builds and runs, first on every page | 158 | <Header |
| 159 | project={project} | |
| 160 | isPrivate={repo.isPrivate} | |
| 161 | namespace={repo.namespace} | |
| 162 | name={repo.name} | |
| 163 | description={null} | |
| 164 | large | |
| 165 | /> | |
| 166 | {description && <p className="mt-2 max-w-2xl text-sm text-muted">{description}</p>} | |
| 167 | <nav className="mt-5 flex gap-6 overflow-x-auto"> | |
| 168 | <Tab to={base} end icon={<LayoutGrid size={15} />}> | |
| 169 | Overview | |
| 170 | </Tab> | |
| 171 | <Tab to={`${base}/code`} also={`${base}/tree`} icon={<Code2 size={15} />}> | |
| API and MCP server, Rust identity service, registration, site redesign | 172 | Code |
| 173 | </Tab> | |
| Issues and pull requests replace intents and attempts | 174 | <Tab to={`${base}/issues`} icon={<CircleDot size={15} />} count={open.issues}> |
| 175 | Issues | |
| 176 | </Tab> | |
| Projects: what a workspace builds and runs, first on every page | 177 | <Tab to={`${base}/pulls`} also={`${base}/pull`} icon={<GitPullRequest size={15} />} count={open.pulls}> |
| Issues and pull requests replace intents and attempts | 178 | Pull requests |
| API and MCP server, Rust identity service, registration, site redesign | 179 | </Tab> |
| 180 | <Tab to={`${base}/commits`} icon={<History size={15} />}> | |
| 181 | Commits | |
| 182 | </Tab> | |
| Agents as a team: lifecycle, merge queue, billing and a new shell | 183 | {member && ( |
| 184 | <Tab to={`${base}/plans`} icon={<ListTree size={15} />}> | |
| 185 | Plan | |
| 186 | </Tab> | |
| 187 | )} | |
| 188 | {member && ( | |
| Projects: what a workspace builds and runs, first on every page | 189 | <Tab to={`${base}/deployments`} icon={<Rocket size={15} />}> |
| 190 | Deployments | |
| 191 | </Tab> | |
| 192 | )} | |
| 193 | {member && ( | |
| Agents as a team: lifecycle, merge queue, billing and a new shell | 194 | <Tab to={`${base}/settings`} icon={<Settings size={15} />}> |
| 195 | Settings | |
| 196 | </Tab> | |
| 197 | )} | |
| API and MCP server, Rust identity service, registration, site redesign | 198 | </nav> |
| 199 | </div> | |
| 200 | </div> | |
| 201 | <div className="mx-auto max-w-6xl px-4 py-6"> | |
| 202 | <Outlet /> | |
| 203 | </div> | |
| 204 | </> | |
| Initial g1t: services, event bus, intents and attempts | 205 | ); |
| 206 | } |