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 | ||
| Search across all of g1t, Explore, and a command palette | 50 | /** A repository's topics, each a way into Explore. */ |
| 51 | function Topics({ topics }: { topics: string[] | undefined }) { | |
| 52 | if (!topics?.length) return null; | |
| 53 | return ( | |
| 54 | <div className="mt-2 flex flex-wrap gap-1.5"> | |
| 55 | {topics.map((topic) => ( | |
| 56 | <Link | |
| 57 | key={topic} | |
| 58 | to={`/explore?topic=${encodeURIComponent(topic)}`} | |
| 59 | className="rounded-full bg-accent/10 px-2 py-px text-xs text-accent ring-1 ring-accent/30 transition-colors hover:bg-accent/20" | |
| 60 | > | |
| 61 | {topic} | |
| 62 | </Link> | |
| 63 | ))} | |
| 64 | </div> | |
| 65 | ); | |
| 66 | } | |
| 67 | ||
| Projects: what a workspace builds and runs, first on every page | 68 | function Header({ project, isPrivate, namespace, name, description, large }: { |
| 69 | project: Project | null; | |
| 70 | isPrivate: boolean; | |
| 71 | namespace: string; | |
| 72 | name: string; | |
| 73 | description: string | null; | |
| 74 | large?: boolean; | |
| 75 | }) { | |
| 76 | const base = `/${namespace}/${name}`; | |
| 77 | return ( | |
| 78 | <div className="flex flex-wrap items-center gap-x-3 gap-y-1"> | |
| 79 | <span | |
| 80 | className={`flex shrink-0 items-center justify-center rounded-md bg-raised text-muted ring-1 ring-line ${large ? "size-8" : "size-6"}`} | |
| 81 | > | |
| 82 | {isPrivate ? <Lock size={large ? 15 : 13} /> : <Box size={large ? 15 : 13} />} | |
| 83 | </span> | |
| 84 | <h1 className={large ? "text-lg" : "text-[0.9375rem]"}> | |
| 85 | <Link to={`/${namespace}`} className="font-mono text-muted hover:text-fg"> | |
| 86 | {namespace} | |
| 87 | </Link> | |
| 88 | <span className="mx-1.5 text-faint">/</span> | |
| 89 | <Link to={base} className="font-semibold hover:underline"> | |
| 90 | {project?.name ?? name} | |
| 91 | </Link> | |
| 92 | </h1> | |
| 93 | <Pill>{isPrivate ? "private" : "public"}</Pill> | |
| 94 | {description && <p className="min-w-0 truncate text-sm text-muted">{description}</p>} | |
| 95 | </div> | |
| 96 | ); | |
| 97 | } | |
| 98 | ||
| A flat project menu with Code first, views as tabs, and Stripe for every owner | 99 | /** |
| 100 | * The views of the page the project is on, as tabs across its top: Files, | |
| 101 | * Commits and what is coming under Code, and so on. Soon tabs open their | |
| 102 | * roadmap page, under the same tabs. | |
| 103 | */ | |
| 104 | function PageTabs({ base, tabs }: { base: string; tabs: PageTab[] }) { | |
| 105 | const { pathname } = useLocation(); | |
| 106 | const rest = pathname.slice(base.length + 1); | |
| 107 | const current = (tab: PageTab) => | |
| 108 | [tab.path, ...(tab.also ?? [])].some((path) => rest === path || rest.startsWith(`${path}/`)); | |
| 109 | return ( | |
| Observability gets its own page; tabs never overflow | 110 | <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 | 111 | {tabs.map((tab) => ( |
| 112 | <NavLink | |
| 113 | key={tab.path} | |
| 114 | to={`${base}/${tab.path}`} | |
| 115 | title={tab.about} | |
| 116 | prefetch="intent" | |
| 117 | className={`flex shrink-0 items-center gap-1.5 border-b-2 px-3 pt-1 pb-2.5 text-sm transition-colors ${ | |
| 118 | current(tab) | |
| 119 | ? "border-accent font-medium text-fg" | |
| 120 | : tab.soon | |
| 121 | ? "border-transparent text-faint hover:text-muted" | |
| 122 | : "border-transparent text-muted hover:text-fg" | |
| 123 | }`} | |
| 124 | > | |
| 125 | {tab.label} | |
| Observability gets its own page; tabs never overflow | 126 | {/* 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 | 127 | {tab.soon && ( |
| Observability gets its own page; tabs never overflow | 128 | <> |
| 129 | <span aria-hidden="true" className="size-1.5 rounded-full bg-accent/70" /> | |
| 130 | <span className="sr-only">(soon)</span> | |
| 131 | </> | |
| A flat project menu with Code first, views as tabs, and Stripe for every owner | 132 | )} |
| 133 | </NavLink> | |
| 134 | ))} | |
| 135 | </nav> | |
| 136 | ); | |
| 137 | } | |
| 138 | ||
| Projects: what a workspace builds and runs, first on every page | 139 | export default function ProjectLayout({ loaderData }: Route.ComponentProps) { |
| 140 | const { repo, project, open, member } = loaderData; | |
| Initial g1t: services, event bus, intents and attempts | 141 | const base = `/${repo.namespace}/${repo.name}`; |
| Agents as a team: lifecycle, merge queue, billing and a new shell | 142 | const signedIn = useRouteLoaderData("root")?.user != null; |
| Projects: what a workspace builds and runs, first on every page | 143 | const description = project?.description ?? repo.description; |
| A flat project menu with Code first, views as tabs, and Stripe for every owner | 144 | const { pathname } = useLocation(); |
| 145 | const tabs = tabsFor(pathname.slice(base.length + 1), member); | |
| Agents as a team: lifecycle, merge queue, billing and a new shell | 146 | if (signedIn) { |
| 147 | return ( | |
| 148 | <> | |
| 149 | <div className="border-b border-line"> | |
| A flat project menu with Code first, views as tabs, and Stripe for every owner | 150 | <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 | 151 | <Header |
| 152 | project={project} | |
| 153 | isPrivate={repo.isPrivate} | |
| 154 | namespace={repo.namespace} | |
| 155 | name={repo.name} | |
| 156 | description={description} | |
| 157 | /> | |
| Search across all of g1t, Explore, and a command palette | 158 | <Topics topics={repo.topics} /> |
| A flat project menu with Code first, views as tabs, and Stripe for every owner | 159 | {tabs && ( |
| 160 | <div className="mt-3"> | |
| 161 | <PageTabs base={base} tabs={tabs} /> | |
| 162 | </div> | |
| 163 | )} | |
| Agents as a team: lifecycle, merge queue, billing and a new shell | 164 | </div> |
| 165 | </div> | |
| 166 | <div className="mx-auto max-w-6xl px-4 py-6 sm:px-6"> | |
| 167 | <Outlet /> | |
| 168 | </div> | |
| 169 | </> | |
| 170 | ); | |
| 171 | } | |
| Initial g1t: services, event bus, intents and attempts | 172 | return ( |
| API and MCP server, Rust identity service, registration, site redesign | 173 | <> |
| Projects: what a workspace builds and runs, first on every page | 174 | {/* The project's own header band, under the site header. */} |
| API and MCP server, Rust identity service, registration, site redesign | 175 | <div className="border-b border-line bg-surface/60"> |
| 176 | <div className="mx-auto max-w-6xl px-4 pt-6"> | |
| Projects: what a workspace builds and runs, first on every page | 177 | <Header |
| 178 | project={project} | |
| 179 | isPrivate={repo.isPrivate} | |
| 180 | namespace={repo.namespace} | |
| 181 | name={repo.name} | |
| 182 | description={null} | |
| 183 | large | |
| 184 | /> | |
| 185 | {description && <p className="mt-2 max-w-2xl text-sm text-muted">{description}</p>} | |
| Search across all of g1t, Explore, and a command palette | 186 | <Topics topics={repo.topics} /> |
| Projects: what a workspace builds and runs, first on every page | 187 | <nav className="mt-5 flex gap-6 overflow-x-auto"> |
| 188 | <Tab to={base} end icon={<LayoutGrid size={15} />}> | |
| 189 | Overview | |
| 190 | </Tab> | |
| 191 | <Tab to={`${base}/code`} also={`${base}/tree`} icon={<Code2 size={15} />}> | |
| API and MCP server, Rust identity service, registration, site redesign | 192 | Code |
| 193 | </Tab> | |
| Issues and pull requests replace intents and attempts | 194 | <Tab to={`${base}/issues`} icon={<CircleDot size={15} />} count={open.issues}> |
| 195 | Issues | |
| 196 | </Tab> | |
| Projects: what a workspace builds and runs, first on every page | 197 | <Tab to={`${base}/pulls`} also={`${base}/pull`} icon={<GitPullRequest size={15} />} count={open.pulls}> |
| Issues and pull requests replace intents and attempts | 198 | Pull requests |
| API and MCP server, Rust identity service, registration, site redesign | 199 | </Tab> |
| 200 | <Tab to={`${base}/commits`} icon={<History size={15} />}> | |
| 201 | Commits | |
| 202 | </Tab> | |
| Agents as a team: lifecycle, merge queue, billing and a new shell | 203 | {member && ( |
| 204 | <Tab to={`${base}/plans`} icon={<ListTree size={15} />}> | |
| 205 | Plan | |
| 206 | </Tab> | |
| 207 | )} | |
| 208 | {member && ( | |
| Projects: what a workspace builds and runs, first on every page | 209 | <Tab to={`${base}/deployments`} icon={<Rocket size={15} />}> |
| 210 | Deployments | |
| 211 | </Tab> | |
| 212 | )} | |
| 213 | {member && ( | |
| Agents as a team: lifecycle, merge queue, billing and a new shell | 214 | <Tab to={`${base}/settings`} icon={<Settings size={15} />}> |
| 215 | Settings | |
| 216 | </Tab> | |
| 217 | )} | |
| API and MCP server, Rust identity service, registration, site redesign | 218 | </nav> |
| 219 | </div> | |
| 220 | </div> | |
| 221 | <div className="mx-auto max-w-6xl px-4 py-6"> | |
| 222 | <Outlet /> | |
| 223 | </div> | |
| 224 | </> | |
| Initial g1t: services, event bus, intents and attempts | 225 | ); |
| 226 | } |