24 lines · 1.4 KBRaw
| 1 | import { data } from "react-router"; |
| 2 | import type { Route } from "./+types/repo-tree"; |
| 3 | import { splatSegments } from "@refs/backend/contract"; |
| 4 | import { TreeView } from "@refs/design-system"; |
| 5 | import { useLastChanges } from "../components/last-changes"; |
| 6 | import { commitCheck } from "../lib/commit-check"; |
| 7 | import { found, refs, fullName, nowSeconds } from "../lib/session"; |
| 8 | |
| 9 | export const meta: Route.MetaFunction = ({ params }) => [{ title: `${params["*"]} · ${fullName(params)} · refs` }]; |
| 10 | |
| 11 | export 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 | |
| 20 | export 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 | } |