| 1 | import type { Route } from "./+types/code"; |
| 2 | import { TreeView } from "../../components/repo-view"; |
| 3 | import { page } from "../../lib/meta"; |
| 4 | import { lastCommitsFor } from "../../lib/last-commits.server"; |
| 5 | import { repos } from "../../lib/services.server"; |
| 6 | import { getViewer, unwrap } from "../../lib/session.server"; |
| 7 | |
| 8 | export function meta({ params, ...args }: Route.MetaArgs) { |
| 9 | return page(args, { title: `Code · ${params.owner}/${params.repo} · g1t` }); |
| 10 | } |
| 11 | |
| 12 | export async function loader({ params, context }: Route.LoaderArgs) { |
| 13 | const path = { namespace: params.owner, name: params.repo }; |
| 14 | const viewer = getViewer(context); |
| 15 | const [tree, branches] = await Promise.all([ |
| 16 | repos.tree(path, viewer, null, ""), |
| 17 | // For the branch menu; the page still shows without it. |
| 18 | repos.branches(path, viewer).catch(() => null), |
| 19 | ]); |
| 20 | // Each entry's last commit walks history: streamed in after the list. |
| 21 | const lastCommits = lastCommitsFor(path, viewer, null, ""); |
| 22 | return { tree: unwrap(tree), branches: branches?.ok ? branches.value : null, lastCommits }; |
| 23 | } |
| 24 | |
| 25 | export default function Code({ loaderData }: Route.ComponentProps) { |
| 26 | return <TreeView tree={loaderData.tree} branches={loaderData.branches} lastCommits={loaderData.lastCommits} />; |
| 27 | } |