Skip to content
31 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 { lastCommitsFor } from "../../lib/last-commits.server";
6import { repos } from "../../lib/services.server";
7import { getViewer, unwrap } from "../../lib/session.server";
8
9export function meta({ params, ...args }: Route.MetaArgs) {
10 return page(args, { title: `Code · ${params.owner}/${params.repo} · g1t` });
11}
12
13export async function loader({ params, context }: Route.LoaderArgs) {
14 const path = { namespace: params.owner, name: params.repo };
15 const viewer = getViewer(context);
16 const [tree, branches] = await Promise.all([
17 repos.tree(path, viewer, null, ""),
18 // For the branch menu; the page still shows without it.
19 repos.branches(path, viewer).catch(() => null),
20 ]);
21 // Each entry's last commit walks history: streamed in after the list.
22 const lastCommits = lastCommitsFor(path, viewer, null, "");
23 const found = unwrap(tree);
24 // The latest commit's checks: streamed in beside it.
25 const checks = commitChecksFor(path, viewer, [found.head?.hash]);
26 return { tree: found, branches: branches?.ok ? branches.value : null, lastCommits, checks };
27}
28
29export default function Code({ loaderData }: Route.ComponentProps) {
30 return <TreeView tree={loaderData.tree} branches={loaderData.branches} lastCommits={loaderData.lastCommits} checks={loaderData.checks} />;
31}