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