Skip to content
54 linesCodeBlameRaw
1import type { Route } from "./+types/code";
2import { TreeView } from "../../components/repo-view";
3import { page } from "../../lib/meta";
4import { commitChecksFor } from "../../lib/commit-checks.server";
5import { aboutFor } from "../../lib/about.server";
6import { environmentsFor } from "../../lib/deployments.server";
7import { lastCommitsFor } from "../../lib/last-commits.server";
8import { showOneCommit } from "../../lib/commit-people.server";
9import { repos } from "../../lib/services.server";
10import { getViewer, unwrap } from "../../lib/session.server";
11import { projectHomepage } from "../../lib/about";
12import { useProject } from "./layout";
13
14export function meta({ params, ...args }: Route.MetaArgs) {
15 return page(args, { title: `Code · ${params.owner}/${params.repo} · g1t` });
16}
17
18export async function loader({ params, context }: Route.LoaderArgs) {
19 const path = { namespace: params.owner, name: params.repo };
20 const viewer = getViewer(context);
21 const [tree, branches, environments] = await Promise.all([
22 repos.tree(path, viewer, null, ""),
23 // For the branch menu; the page still shows without it.
24 repos.branches(path, viewer).catch(() => null),
25 // For the About sidebar's Deployments panel; null without any.
26 environmentsFor(path, viewer),
27 ]);
28 // Each entry's last commit walks history: streamed in after the list.
29 const lastCommits = lastCommitsFor(path, viewer, null, "");
30 const found = unwrap(tree);
31 // The latest commit's author, as their account where there is one.
32 const value = { ...found, head: await showOneCommit(found.head) };
33 // The About beside the files, streamed in after them.
34 const about = value.head ? aboutFor(path, viewer, value.repo.id) : null;
35 // The latest commit's checks: streamed in beside it.
36 const checks = commitChecksFor(path, viewer, [value.head?.hash]);
37 return { tree: value, branches: branches?.ok ? branches.value : null, lastCommits, about, deployments: environments, checks };
38}
39
40export default function Code({ loaderData }: Route.ComponentProps) {
41 const project = useProject();
42 return (
43 <TreeView
44 tree={loaderData.tree}
45 branches={loaderData.branches}
46 lastCommits={loaderData.lastCommits}
47 checks={loaderData.checks}
48 about={loaderData.about}
49 canPush={Boolean(project?.access.can.push)}
50 homepage={projectHomepage(project?.project ?? null)}
51 deployments={loaderData.deployments}
52 />
53 );
54}