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