Skip to content
refs
History
24 lines · 1.4 KBRaw
1import { data } from "react-router";
2import type { Route } from "./+types/repo-tree";
3import { splatSegments } from "@refs/backend/contract";
4import { TreeView } from "@refs/design-system";
5import { useLastChanges } from "../components/last-changes";
6import { commitCheck } from "../lib/commit-check";
7import { found, refs, fullName, nowSeconds } from "../lib/session";
8
9export const meta: Route.MetaFunction = ({ params }) => [{ title: `${params["*"]} · ${fullName(params)} · refs` }];
10
11export async function loader({ params, context }: Route.LoaderArgs) {
12 const segments = splatSegments(params["*"]);
13 if (!segments) throw data(null, { status: 404 });
14 const repo = await found(refs(context).repo(fullName(params)));
15 const [tree, refList] = await found(Promise.all([repo.tree(segments), repo.refs()]));
16 const check = commitCheck(repo.summary.name, await repo.ci().runs({ sha: tree.commit.hash, limit: 10 }));
17 return { repo: repo.summary.name, cloneUrl: repo.summary.cloneUrl, refs: refList, tree, check, now: nowSeconds() };
18}
19
20export default function RepoTree({ loaderData }: Route.ComponentProps) {
21 const { repo, cloneUrl, refs: refList, tree, now } = loaderData;
22 const last = useLastChanges(repo, tree.location.ref, tree.location.path);
23 return <TreeView repo={repo} cloneUrl={cloneUrl} refs={refList} current={tree.location.ref} path={tree.location.path} tree={tree} now={now} last={last} check={loaderData.check} />;
24}