Skip to content
refs
28 lines · 1.8 KBRaw
1import { Outlet, useLocation } from "react-router";
2import type { Route } from "./+types/repo";
3import { RepoTabs, type RepoTab } from "@refs/design-system";
4import { AppShell } from "../components/shell";
5import { PendingView, under, useIntendedPath } from "../components/pending";
6import { found, refs, fullName } from "../lib/session";
7
8export async function loader({ params, context }: Route.LoaderArgs) {
9 const handle = refs(context);
10 const repo = await found(handle.repo(fullName(params)));
11 return { repo: repo.summary, signedIn: handle.viewer.person !== null };
12}
13
14export default function RepoLayout({ loaderData }: Route.ComponentProps) {
15 const { repo, signedIn } = loaderData;
16 const { pathname } = useLocation();
17 const intended = useIntendedPath();
18 const current: RepoTab = intended === `/${repo.name}/map` ? "map" : intended.startsWith(`/${repo.name}/tasks`) ? "tasks" : intended.startsWith(`/${repo.name}/pulls`) || intended === `/${repo.name}/compare` ? "pulls" : intended.startsWith(`/${repo.name}/agents`) ? "agents" : intended.startsWith(`/${repo.name}/runs`) ? "runs" : intended.startsWith(`/${repo.name}/settings`) ? "settings" : "code";
19 const crumbs = [{ label: repo.name.slice(repo.name.indexOf("/") + 1), href: `/${repo.name}` }];
20 const pull = pathname.match(/\/pulls\/(\d+)/)?.[1];
21 return (
22 <AppShell crumbs={pull ? [...crumbs, { label: "Pull requests", href: `/${repo.name}/pulls` }, { label: `#${pull}`, href: `/${repo.name}/pulls/${pull}` }] : crumbs} subnav={pull ? undefined : <RepoTabs repo={repo} current={current} signedIn={signedIn} />} keeps={`/${repo.name}`} full={pathname === `/${repo.name}/map` || /\/pulls\/\d+\/map$/.test(pathname)}>
23 <PendingView covers={(to) => under(to, `/${repo.name}`) && !(pull !== undefined && under(to, `/${repo.name}/pulls/${pull}`))}>
24 <Outlet />
25 </PendingView>
26 </AppShell>
27 );
28}