pr_01m47d15m3e54sn21z27rpy5n9/apps/web/app/routes/repo/layout.tsx

152 lines5,502 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.

Projects: what a workspace builds and runs, first on every page1import { Box, CircleDot, Code2, GitPullRequest, History, LayoutGrid, ListTree, Lock, Rocket, Settings } from "lucide-react";
2import { Link, Outlet, data, useRouteLoaderData } from "react-router";
3
4import type { Project } from "@g1t/contracts";
Initial g1t: services, event bus, intents and attempts5
6import type { Route } from "./+types/layout";
Agents as a team: lifecycle, merge queue, billing and a new shell7import { Pill, TabLink as Tab } from "../../components/ui";
Projects: what a workspace builds and runs, first on every page8import { projects, repos, work } from "../../lib/services.server";
Agents as a team: lifecycle, merge queue, billing and a new shell9import { getViewer, roleIn, unwrap } from "../../lib/session.server";
Initial g1t: services, event bus, intents and attempts10
Projects: what a workspace builds and runs, first on every page11export function meta({ loaderData: loaded, params }: Route.MetaArgs) {
12 return [{ title: `${loaded?.project?.name ?? params.repo} · ${params.owner} · g1t` }];
Initial g1t: services, event bus, intents and attempts13}
14
15export async function loader({ params, context }: Route.LoaderArgs) {
16 const viewer = getViewer(context);
17 const path = { namespace: params.owner, name: params.repo };
Projects: what a workspace builds and runs, first on every page18 const [repo, counts, found] = await Promise.all([
Rust repos service with shipping; pull requests kept in the model19 repos.get(path, viewer),
Issues and pull requests replace intents and attempts20 work.counts(path, viewer),
Projects: what a workspace builds and runs, first on every page21 projects.get(params.owner, params.repo, viewer),
Initial g1t: services, event bus, intents and attempts22 ]);
Projects: what a workspace builds and runs, first on every page23 if (!repo.ok && !found.ok) throw data(null, { status: 404 });
24 let project: Project | null = found.ok ? found.value : null;
25 // A repository made a moment ago, before its project: make it now.
26 if (!project && repo.ok && !repo.value.forkOf) {
27 const own = await projects.byRepo(repo.value.id);
28 project = own.find((p) => p.slug === params.repo.toLowerCase()) ?? own[0] ?? null;
29 }
Initial g1t: services, event bus, intents and attempts30 return {
31 repo: unwrap(repo),
Projects: what a workspace builds and runs, first on every page32 project,
Issues and pull requests replace intents and attempts33 open: counts.ok ? counts.value : { issues: 0, pulls: 0 },
Agents as a team: lifecycle, merge queue, billing and a new shell34 member: roleIn(viewer, params.owner) != null,
Initial g1t: services, event bus, intents and attempts35 };
36}
37
Projects: what a workspace builds and runs, first on every page38/** The project the page is in, for the pages under it. */
39export function useProject() {
40 return useRouteLoaderData<typeof loader>("routes/repo/layout");
41}
42
43function Header({ project, isPrivate, namespace, name, description, large }: {
44 project: Project | null;
45 isPrivate: boolean;
46 namespace: string;
47 name: string;
48 description: string | null;
49 large?: boolean;
50}) {
51 const base = `/${namespace}/${name}`;
52 return (
53 <div className="flex flex-wrap items-center gap-x-3 gap-y-1">
54 <span
55 className={`flex shrink-0 items-center justify-center rounded-md bg-raised text-muted ring-1 ring-line ${large ? "size-8" : "size-6"}`}
56 >
57 {isPrivate ? <Lock size={large ? 15 : 13} /> : <Box size={large ? 15 : 13} />}
58 </span>
59 <h1 className={large ? "text-lg" : "text-[0.9375rem]"}>
60 <Link to={`/${namespace}`} className="font-mono text-muted hover:text-fg">
61 {namespace}
62 </Link>
63 <span className="mx-1.5 text-faint">/</span>
64 <Link to={base} className="font-semibold hover:underline">
65 {project?.name ?? name}
66 </Link>
67 </h1>
68 <Pill>{isPrivate ? "private" : "public"}</Pill>
69 {description && <p className="min-w-0 truncate text-sm text-muted">{description}</p>}
70 </div>
71 );
72}
73
74export default function ProjectLayout({ loaderData }: Route.ComponentProps) {
75 const { repo, project, open, member } = loaderData;
Initial g1t: services, event bus, intents and attempts76 const base = `/${repo.namespace}/${repo.name}`;
Agents as a team: lifecycle, merge queue, billing and a new shell77 const signedIn = useRouteLoaderData("root")?.user != null;
Projects: what a workspace builds and runs, first on every page78 const description = project?.description ?? repo.description;
Agents as a team: lifecycle, merge queue, billing and a new shell79 if (signedIn) {
80 return (
81 <>
82 <div className="border-b border-line">
Projects: what a workspace builds and runs, first on every page83 <div className="mx-auto max-w-6xl px-4 py-3 sm:px-6">
84 <Header
85 project={project}
86 isPrivate={repo.isPrivate}
87 namespace={repo.namespace}
88 name={repo.name}
89 description={description}
90 />
Agents as a team: lifecycle, merge queue, billing and a new shell91 </div>
92 </div>
93 <div className="mx-auto max-w-6xl px-4 py-6 sm:px-6">
94 <Outlet />
95 </div>
96 </>
97 );
98 }
Initial g1t: services, event bus, intents and attempts99 return (
API and MCP server, Rust identity service, registration, site redesign100 <>
Projects: what a workspace builds and runs, first on every page101 {/* The project's own header band, under the site header. */}
API and MCP server, Rust identity service, registration, site redesign102 <div className="border-b border-line bg-surface/60">
103 <div className="mx-auto max-w-6xl px-4 pt-6">
Projects: what a workspace builds and runs, first on every page104 <Header
105 project={project}
106 isPrivate={repo.isPrivate}
107 namespace={repo.namespace}
108 name={repo.name}
109 description={null}
110 large
111 />
112 {description && <p className="mt-2 max-w-2xl text-sm text-muted">{description}</p>}
113 <nav className="mt-5 flex gap-6 overflow-x-auto">
114 <Tab to={base} end icon={<LayoutGrid size={15} />}>
115 Overview
116 </Tab>
117 <Tab to={`${base}/code`} also={`${base}/tree`} icon={<Code2 size={15} />}>
API and MCP server, Rust identity service, registration, site redesign118 Code
119 </Tab>
Issues and pull requests replace intents and attempts120 <Tab to={`${base}/issues`} icon={<CircleDot size={15} />} count={open.issues}>
121 Issues
122 </Tab>
Projects: what a workspace builds and runs, first on every page123 <Tab to={`${base}/pulls`} also={`${base}/pull`} icon={<GitPullRequest size={15} />} count={open.pulls}>
Issues and pull requests replace intents and attempts124 Pull requests
API and MCP server, Rust identity service, registration, site redesign125 </Tab>
126 <Tab to={`${base}/commits`} icon={<History size={15} />}>
127 Commits
128 </Tab>
Agents as a team: lifecycle, merge queue, billing and a new shell129 {member && (
130 <Tab to={`${base}/plans`} icon={<ListTree size={15} />}>
131 Plan
132 </Tab>
133 )}
134 {member && (
Projects: what a workspace builds and runs, first on every page135 <Tab to={`${base}/deployments`} icon={<Rocket size={15} />}>
136 Deployments
137 </Tab>
138 )}
139 {member && (
Agents as a team: lifecycle, merge queue, billing and a new shell140 <Tab to={`${base}/settings`} icon={<Settings size={15} />}>
141 Settings
142 </Tab>
143 )}
API and MCP server, Rust identity service, registration, site redesign144 </nav>
145 </div>
146 </div>
147 <div className="mx-auto max-w-6xl px-4 py-6">
148 <Outlet />
149 </div>
150 </>
Initial g1t: services, event bus, intents and attempts151 );
152}