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

213 lines8,667 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.

Team plan, an open-source pool, monthly trials and honest metering; the sidebar for everyone; a workspace that stays put1import { Box, Lock } from "lucide-react";
Fast pages, required checks on the branch, self-hosted runners, honest incidents2import { Link, NavLink, Outlet, type ShouldRevalidateFunctionArgs, data, useLocation, useRouteLoaderData } from "react-router";
Projects: what a workspace builds and runs, first on every page3
4import type { Project } from "@g1t/contracts";
Initial g1t: services, event bus, intents and attempts5
6import type { Route } from "./+types/layout";
Social cards for every page: og.g1t.sh7import { page } from "../../lib/meta";
A flat project menu with Code first, views as tabs, and Stripe for every owner8import { type Tab as PageTab, tabsFor } from "../../lib/project-nav";
Team plan, an open-source pool, monthly trials and honest metering; the sidebar for everyone; a workspace that stays put9import { Pill } from "../../components/ui";
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look10import { ArchivedBanner } from "../../components/repo-lifecycle";
status.g1t.sh with incident management, invites that land you in the workspace, settings as pages, usage without quotas11import { WelcomeBanner } from "../../components/welcome";
12import { clearWelcome, welcomes } from "../../lib/invites";
Team plan, an open-source pool, monthly trials and honest metering; the sidebar for everyone; a workspace that stays put13import { notFound } from "../../lib/not-found.server";
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look14import { redirectIfRenamed, redirectIfTransferred } from "../../lib/renamed.server";
Fast pages, required checks on the branch, self-hosted runners, honest incidents15import { accessFor, countsFor, repoFor } from "../../lib/access.server";
16import { projects } from "../../lib/services.server";
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look17import { getViewer, unwrap } from "../../lib/session.server";
Initial g1t: services, event bus, intents and attempts18
Social cards for every page: og.g1t.sh19export function meta({ loaderData: loaded, params, ...args }: Route.MetaArgs) {
20 return page(args, { title: `${loaded?.project?.name ?? params.repo} · ${params.owner} · g1t` });
Initial g1t: services, event bus, intents and attempts21}
22
Agents and memory, checks and conflicts, profiles, slug renames, custom domains23export async function loader({ params, context, request }: Route.LoaderArgs) {
Initial g1t: services, event bus, intents and attempts24 const viewer = getViewer(context);
25 const path = { namespace: params.owner, name: params.repo };
Projects: what a workspace builds and runs, first on every page26 const [repo, counts, found] = await Promise.all([
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look27 repoFor(context, params),
Fast pages, required checks on the branch, self-hosted runners, honest incidents28 countsFor(context, params),
Projects: what a workspace builds and runs, first on every page29 projects.get(params.owner, params.repo, viewer),
Initial g1t: services, event bus, intents and attempts30 ]);
Agents and memory, checks and conflicts, profiles, slug renames, custom domains31 if (!repo.ok && !found.ok) {
32 // Under a workspace's old name, after a rename: the project is at the new one.
33 await redirectIfRenamed(request, params.owner);
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look34 // A repository transferred to another workspace: it is there now.
35 await redirectIfTransferred(request, params.owner, params.repo, viewer);
Team plan, an open-source pool, monthly trials and honest metering; the sidebar for everyone; a workspace that stays put36 throw notFound("project");
Agents and memory, checks and conflicts, profiles, slug renames, custom domains37 }
Projects: what a workspace builds and runs, first on every page38 let project: Project | null = found.ok ? found.value : null;
39 // A repository made a moment ago, before its project: make it now.
40 if (!project && repo.ok && !repo.value.forkOf) {
41 const own = await projects.byRepo(repo.value.id);
42 project = own.find((p) => p.slug === params.repo.toLowerCase()) ?? own[0] ?? null;
43 }
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look44 const value = unwrap(repo);
45 // The viewer's role on the repository and what it lets them do, for the
46 // pages under it and the sidebar.
47 const access = accessFor(viewer, value);
status.g1t.sh with incident management, invites that land you in the workspace, settings as pages, usage without quotas48 // Just given access with an invite: welcomed once (routes/invite.tsx).
49 const welcome = Boolean(access.role) && welcomes(request.headers.get("cookie"), `${value.namespace}/${value.name}`);
50 const headers = welcome ? { "Set-Cookie": clearWelcome(new URL(request.url).protocol === "https:") } : undefined;
51 return data({
52 welcome,
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look53 repo: value,
Projects: what a workspace builds and runs, first on every page54 project,
Issues and pull requests replace intents and attempts55 open: counts.ok ? counts.value : { issues: 0, pulls: 0 },
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look56 access,
57 member: access.insider,
status.g1t.sh with incident management, invites that land you in the workspace, settings as pages, usage without quotas58 }, { headers });
Initial g1t: services, event bus, intents and attempts59}
60
Fast pages, required checks on the branch, self-hosted runners, honest incidents61/**
62 * The project's header, tabs and the viewer's role change with the project
63 * or after something was submitted, not from one page of it to the next,
64 * nor when a page refreshes itself.
65 */
66export function shouldRevalidate({ currentParams, nextParams, formMethod, defaultShouldRevalidate }: ShouldRevalidateFunctionArgs) {
67 if (formMethod && formMethod !== "GET") return defaultShouldRevalidate;
68 return currentParams.owner !== nextParams.owner || currentParams.repo !== nextParams.repo;
69}
70
Projects: what a workspace builds and runs, first on every page71/** The project the page is in, for the pages under it. */
72export function useProject() {
73 return useRouteLoaderData<typeof loader>("routes/repo/layout");
74}
75
Search across all of g1t, Explore, and a command palette76/** A repository's topics, each a way into Explore. */
77function Topics({ topics }: { topics: string[] | undefined }) {
78 if (!topics?.length) return null;
79 return (
80 <div className="mt-2 flex flex-wrap gap-1.5">
81 {topics.map((topic) => (
82 <Link
83 key={topic}
84 to={`/explore?topic=${encodeURIComponent(topic)}`}
85 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"
86 >
87 {topic}
88 </Link>
89 ))}
90 </div>
91 );
92}
93
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look94function Header({ project, isPrivate, archived, namespace, name, description, large }: {
Projects: what a workspace builds and runs, first on every page95 project: Project | null;
96 isPrivate: boolean;
97 namespace: string;
98 name: string;
99 description: string | null;
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look100 archived?: boolean;
Projects: what a workspace builds and runs, first on every page101 large?: boolean;
102}) {
103 const base = `/${namespace}/${name}`;
104 return (
105 <div className="flex flex-wrap items-center gap-x-3 gap-y-1">
106 <span
107 className={`flex shrink-0 items-center justify-center rounded-md bg-raised text-muted ring-1 ring-line ${large ? "size-8" : "size-6"}`}
108 >
109 {isPrivate ? <Lock size={large ? 15 : 13} /> : <Box size={large ? 15 : 13} />}
110 </span>
111 <h1 className={large ? "text-lg" : "text-[0.9375rem]"}>
112 <Link to={`/${namespace}`} className="font-mono text-muted hover:text-fg">
113 {namespace}
114 </Link>
115 <span className="mx-1.5 text-faint">/</span>
116 <Link to={base} className="font-semibold hover:underline">
117 {project?.name ?? name}
118 </Link>
119 </h1>
120 <Pill>{isPrivate ? "private" : "public"}</Pill>
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look121 {archived && <Pill>archived</Pill>}
Projects: what a workspace builds and runs, first on every page122 {description && <p className="min-w-0 truncate text-sm text-muted">{description}</p>}
123 </div>
124 );
125}
126
A flat project menu with Code first, views as tabs, and Stripe for every owner127/**
128 * The views of the page the project is on, as tabs across its top: Files,
129 * Commits and what is coming under Code, and so on. Soon tabs open their
130 * roadmap page, under the same tabs.
131 */
132function PageTabs({ base, tabs }: { base: string; tabs: PageTab[] }) {
133 const { pathname } = useLocation();
134 const rest = pathname.slice(base.length + 1);
135 const current = (tab: PageTab) =>
136 [tab.path, ...(tab.also ?? [])].some((path) => rest === path || rest.startsWith(`${path}/`));
137 return (
Team plan, an open-source pool, monthly trials and honest metering; the sidebar for everyone; a workspace that stays put138 <nav aria-label="Views" className="relative -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 owner139 {tabs.map((tab) => (
140 <NavLink
141 key={tab.path}
142 to={`${base}/${tab.path}`}
143 title={tab.about}
144 prefetch="intent"
145 className={`flex shrink-0 items-center gap-1.5 border-b-2 px-3 pt-1 pb-2.5 text-sm transition-colors ${
146 current(tab)
147 ? "border-accent font-medium text-fg"
148 : tab.soon
149 ? "border-transparent text-faint hover:text-muted"
150 : "border-transparent text-muted hover:text-fg"
151 }`}
152 >
153 {tab.label}
Observability gets its own page; tabs never overflow154 {/* 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 owner155 {tab.soon && (
Observability gets its own page; tabs never overflow156 <>
157 <span aria-hidden="true" className="size-1.5 rounded-full bg-accent/70" />
158 <span className="sr-only">(soon)</span>
159 </>
A flat project menu with Code first, views as tabs, and Stripe for every owner160 )}
161 </NavLink>
162 ))}
163 </nav>
164 );
165}
166
Projects: what a workspace builds and runs, first on every page167export default function ProjectLayout({ loaderData }: Route.ComponentProps) {
status.g1t.sh with incident management, invites that land you in the workspace, settings as pages, usage without quotas168 const { repo, project, member, access, welcome } = loaderData;
Initial g1t: services, event bus, intents and attempts169 const base = `/${repo.namespace}/${repo.name}`;
Fast pages, required checks on the branch, self-hosted runners, honest incidents170 // The project's own description, else the repository's as it is now.
171 const description = (project && !project.descriptionInherited ? project.description : null) ?? repo.description;
A flat project menu with Code first, views as tabs, and Stripe for every owner172 const { pathname } = useLocation();
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look173 const tabs = tabsFor(pathname.slice(base.length + 1), member, access.can);
Team plan, an open-source pool, monthly trials and honest metering; the sidebar for everyone; a workspace that stays put174 // Everyone, signed in or not, finds the project's pages in the sidebar;
175 // the page shows its name, and the views of the page it is on as tabs.
Initial g1t: services, event bus, intents and attempts176 return (
API and MCP server, Rust identity service, registration, site redesign177 <>
Team plan, an open-source pool, monthly trials and honest metering; the sidebar for everyone; a workspace that stays put178 <div className="border-b border-line">
179 <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 page180 <Header
181 project={project}
182 isPrivate={repo.isPrivate}
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look183 archived={Boolean(repo.archivedAt)}
Projects: what a workspace builds and runs, first on every page184 namespace={repo.namespace}
185 name={repo.name}
Team plan, an open-source pool, monthly trials and honest metering; the sidebar for everyone; a workspace that stays put186 description={description}
Projects: what a workspace builds and runs, first on every page187 />
Search across all of g1t, Explore, and a command palette188 <Topics topics={repo.topics} />
Team plan, an open-source pool, monthly trials and honest metering; the sidebar for everyone; a workspace that stays put189 {tabs && (
190 <div className="mt-3">
191 <PageTabs base={base} tabs={tabs} />
192 </div>
193 )}
API and MCP server, Rust identity service, registration, site redesign194 </div>
195 </div>
Team plan, an open-source pool, monthly trials and honest metering; the sidebar for everyone; a workspace that stays put196 <div className="mx-auto max-w-6xl px-4 py-6 sm:px-6">
status.g1t.sh with incident management, invites that land you in the workspace, settings as pages, usage without quotas197 {welcome && (
198 <div className="mb-6">
199 <WelcomeBanner title={`You're in ${repo.namespace}/${repo.name}`}>
200 You have the {access.role} role on it now. Its code, issues and pull requests are yours to work on.
201 </WelcomeBanner>
202 </div>
203 )}
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look204 {repo.archivedAt && (
205 <div className="mb-6">
206 <ArchivedBanner base={base} owner={access.can.administer} settings={/^settings(\/|$)/.test(pathname.slice(base.length + 1))} />
207 </div>
208 )}
API and MCP server, Rust identity service, registration, site redesign209 <Outlet />
210 </div>
211 </>
Initial g1t: services, event bus, intents and attempts212 );
213}