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