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

189 lines7,226 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";
2import { Link, NavLink, Outlet, 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";
Team plan, an open-source pool, monthly trials and honest metering; the sidebar for everyone; a workspace that stays put11import { notFound } from "../../lib/not-found.server";
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look12import { redirectIfRenamed, redirectIfTransferred } from "../../lib/renamed.server";
13import { accessFor, repoFor } from "../../lib/access.server";
14import { projects, work } from "../../lib/services.server";
15import { getViewer, unwrap } from "../../lib/session.server";
Initial g1t: services, event bus, intents and attempts16
Social cards for every page: og.g1t.sh17export function meta({ loaderData: loaded, params, ...args }: Route.MetaArgs) {
18 return page(args, { title: `${loaded?.project?.name ?? params.repo} · ${params.owner} · g1t` });
Initial g1t: services, event bus, intents and attempts19}
20
Agents and memory, checks and conflicts, profiles, slug renames, custom domains21export async function loader({ params, context, request }: Route.LoaderArgs) {
Initial g1t: services, event bus, intents and attempts22 const viewer = getViewer(context);
23 const path = { namespace: params.owner, name: params.repo };
Projects: what a workspace builds and runs, first on every page24 const [repo, counts, found] = await Promise.all([
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look25 repoFor(context, params),
Issues and pull requests replace intents and attempts26 work.counts(path, viewer),
Projects: what a workspace builds and runs, first on every page27 projects.get(params.owner, params.repo, viewer),
Initial g1t: services, event bus, intents and attempts28 ]);
Agents and memory, checks and conflicts, profiles, slug renames, custom domains29 if (!repo.ok && !found.ok) {
30 // Under a workspace's old name, after a rename: the project is at the new one.
31 await redirectIfRenamed(request, params.owner);
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look32 // A repository transferred to another workspace: it is there now.
33 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 put34 throw notFound("project");
Agents and memory, checks and conflicts, profiles, slug renames, custom domains35 }
Projects: what a workspace builds and runs, first on every page36 let project: Project | null = found.ok ? found.value : null;
37 // A repository made a moment ago, before its project: make it now.
38 if (!project && repo.ok && !repo.value.forkOf) {
39 const own = await projects.byRepo(repo.value.id);
40 project = own.find((p) => p.slug === params.repo.toLowerCase()) ?? own[0] ?? null;
41 }
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look42 const value = unwrap(repo);
43 // The viewer's role on the repository and what it lets them do, for the
44 // pages under it and the sidebar.
45 const access = accessFor(viewer, value);
Initial g1t: services, event bus, intents and attempts46 return {
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look47 repo: value,
Projects: what a workspace builds and runs, first on every page48 project,
Issues and pull requests replace intents and attempts49 open: counts.ok ? counts.value : { issues: 0, pulls: 0 },
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look50 access,
51 member: access.insider,
Initial g1t: services, event bus, intents and attempts52 };
53}
54
Projects: what a workspace builds and runs, first on every page55/** The project the page is in, for the pages under it. */
56export function useProject() {
57 return useRouteLoaderData<typeof loader>("routes/repo/layout");
58}
59
Search across all of g1t, Explore, and a command palette60/** A repository's topics, each a way into Explore. */
61function Topics({ topics }: { topics: string[] | undefined }) {
62 if (!topics?.length) return null;
63 return (
64 <div className="mt-2 flex flex-wrap gap-1.5">
65 {topics.map((topic) => (
66 <Link
67 key={topic}
68 to={`/explore?topic=${encodeURIComponent(topic)}`}
69 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"
70 >
71 {topic}
72 </Link>
73 ))}
74 </div>
75 );
76}
77
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look78function Header({ project, isPrivate, archived, namespace, name, description, large }: {
Projects: what a workspace builds and runs, first on every page79 project: Project | null;
80 isPrivate: boolean;
81 namespace: string;
82 name: string;
83 description: string | null;
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look84 archived?: boolean;
Projects: what a workspace builds and runs, first on every page85 large?: boolean;
86}) {
87 const base = `/${namespace}/${name}`;
88 return (
89 <div className="flex flex-wrap items-center gap-x-3 gap-y-1">
90 <span
91 className={`flex shrink-0 items-center justify-center rounded-md bg-raised text-muted ring-1 ring-line ${large ? "size-8" : "size-6"}`}
92 >
93 {isPrivate ? <Lock size={large ? 15 : 13} /> : <Box size={large ? 15 : 13} />}
94 </span>
95 <h1 className={large ? "text-lg" : "text-[0.9375rem]"}>
96 <Link to={`/${namespace}`} className="font-mono text-muted hover:text-fg">
97 {namespace}
98 </Link>
99 <span className="mx-1.5 text-faint">/</span>
100 <Link to={base} className="font-semibold hover:underline">
101 {project?.name ?? name}
102 </Link>
103 </h1>
104 <Pill>{isPrivate ? "private" : "public"}</Pill>
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look105 {archived && <Pill>archived</Pill>}
Projects: what a workspace builds and runs, first on every page106 {description && <p className="min-w-0 truncate text-sm text-muted">{description}</p>}
107 </div>
108 );
109}
110
A flat project menu with Code first, views as tabs, and Stripe for every owner111/**
112 * The views of the page the project is on, as tabs across its top: Files,
113 * Commits and what is coming under Code, and so on. Soon tabs open their
114 * roadmap page, under the same tabs.
115 */
116function PageTabs({ base, tabs }: { base: string; tabs: PageTab[] }) {
117 const { pathname } = useLocation();
118 const rest = pathname.slice(base.length + 1);
119 const current = (tab: PageTab) =>
120 [tab.path, ...(tab.also ?? [])].some((path) => rest === path || rest.startsWith(`${path}/`));
121 return (
Team plan, an open-source pool, monthly trials and honest metering; the sidebar for everyone; a workspace that stays put122 <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 owner123 {tabs.map((tab) => (
124 <NavLink
125 key={tab.path}
126 to={`${base}/${tab.path}`}
127 title={tab.about}
128 prefetch="intent"
129 className={`flex shrink-0 items-center gap-1.5 border-b-2 px-3 pt-1 pb-2.5 text-sm transition-colors ${
130 current(tab)
131 ? "border-accent font-medium text-fg"
132 : tab.soon
133 ? "border-transparent text-faint hover:text-muted"
134 : "border-transparent text-muted hover:text-fg"
135 }`}
136 >
137 {tab.label}
Observability gets its own page; tabs never overflow138 {/* 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 owner139 {tab.soon && (
Observability gets its own page; tabs never overflow140 <>
141 <span aria-hidden="true" className="size-1.5 rounded-full bg-accent/70" />
142 <span className="sr-only">(soon)</span>
143 </>
A flat project menu with Code first, views as tabs, and Stripe for every owner144 )}
145 </NavLink>
146 ))}
147 </nav>
148 );
149}
150
Projects: what a workspace builds and runs, first on every page151export default function ProjectLayout({ loaderData }: Route.ComponentProps) {
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look152 const { repo, project, member, access } = loaderData;
Initial g1t: services, event bus, intents and attempts153 const base = `/${repo.namespace}/${repo.name}`;
Projects: what a workspace builds and runs, first on every page154 const description = project?.description ?? repo.description;
A flat project menu with Code first, views as tabs, and Stripe for every owner155 const { pathname } = useLocation();
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look156 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 put157 // Everyone, signed in or not, finds the project's pages in the sidebar;
158 // the page shows its name, and the views of the page it is on as tabs.
Initial g1t: services, event bus, intents and attempts159 return (
API and MCP server, Rust identity service, registration, site redesign160 <>
Team plan, an open-source pool, monthly trials and honest metering; the sidebar for everyone; a workspace that stays put161 <div className="border-b border-line">
162 <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 page163 <Header
164 project={project}
165 isPrivate={repo.isPrivate}
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look166 archived={Boolean(repo.archivedAt)}
Projects: what a workspace builds and runs, first on every page167 namespace={repo.namespace}
168 name={repo.name}
Team plan, an open-source pool, monthly trials and honest metering; the sidebar for everyone; a workspace that stays put169 description={description}
Projects: what a workspace builds and runs, first on every page170 />
Search across all of g1t, Explore, and a command palette171 <Topics topics={repo.topics} />
Team plan, an open-source pool, monthly trials and honest metering; the sidebar for everyone; a workspace that stays put172 {tabs && (
173 <div className="mt-3">
174 <PageTabs base={base} tabs={tabs} />
175 </div>
176 )}
API and MCP server, Rust identity service, registration, site redesign177 </div>
178 </div>
Team plan, an open-source pool, monthly trials and honest metering; the sidebar for everyone; a workspace that stays put179 <div className="mx-auto max-w-6xl px-4 py-6 sm:px-6">
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look180 {repo.archivedAt && (
181 <div className="mb-6">
182 <ArchivedBanner base={base} owner={access.can.administer} settings={/^settings(\/|$)/.test(pathname.slice(base.length + 1))} />
183 </div>
184 )}
API and MCP server, Rust identity service, registration, site redesign185 <Outlet />
186 </div>
187 </>
Initial g1t: services, event bus, intents and attempts188 );
189}