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