FileTree.tsx
| 1 | import type { RepositoryRow } from "../../db/index.ts"; |
| 2 | import type { SessionUser } from "../../middleware/session.ts"; |
| 3 | import type { TreeEntry } from "../../services/git.ts"; |
| 4 | import { Layout } from "../layout.tsx"; |
| 5 | import { RepoHeader } from "../repos/RepoHeader.tsx"; |
| 6 | import { BranchSelector } from "./BranchSelector.tsx"; |
| 7 | import { FileTreeTable } from "./FileTreeTable.tsx"; |
| 8 | import { RepoNav } from "./RepoNav.tsx"; |
| 9 | |
| 10 | interface FileTreeProps { |
| 11 | user: SessionUser | null; |
| 12 | repo: RepositoryRow; |
| 13 | ref: string; |
| 14 | subpath: string; |
| 15 | entries: TreeEntry[]; |
| 16 | branches: string[]; |
| 17 | readmeHtml?: string | null; |
| 18 | readmePath?: string; |
| 19 | } |
| 20 | |
| 21 | export function FileTree({ |
| 22 | user, |
| 23 | repo, |
| 24 | ref: treeRef, |
| 25 | subpath, |
| 26 | entries, |
| 27 | branches, |
| 28 | readmeHtml, |
| 29 | readmePath, |
| 30 | }: FileTreeProps) { |
| 31 | const parts = subpath ? subpath.split("/") : []; |
| 32 | return ( |
| 33 | <Layout |
| 34 | user={user} |
| 35 | title={`${repo.name}${subpath ? `/${subpath}` : ""}`} |
| 36 | > |
| 37 | <div class="container"> |
| 38 | <RepoHeader repo={repo} /> |
| 39 | <RepoNav repo={repo} active="code" user={user} /> |
| 40 | <div class="tree-toolbar"> |
| 41 | <BranchSelector |
| 42 | repoName={repo.name} |
| 43 | branches={branches} |
| 44 | currentRef={treeRef} |
| 45 | view="tree" |
| 46 | path={subpath} |
| 47 | /> |
| 48 | </div> |
| 49 | {subpath && ( |
| 50 | <div class="breadcrumb"> |
| 51 | <a href={`/${repo.name}/tree/${treeRef}`}> |
| 52 | {repo.name} |
| 53 | </a> |
| 54 | {parts.map((part, i) => { |
| 55 | const partPath = parts.slice(0, i + 1).join("/"); |
| 56 | return ( |
| 57 | <> |
| 58 | <span class="breadcrumb-sep">/</span> |
| 59 | <a |
| 60 | href={`/${repo.name}/tree/${treeRef}/${partPath}`} |
| 61 | > |
| 62 | {part} |
| 63 | </a> |
| 64 | </> |
| 65 | ); |
| 66 | })} |
| 67 | </div> |
| 68 | )} |
| 69 | <FileTreeTable |
| 70 | repoName={repo.name} |
| 71 | treeRef={treeRef} |
| 72 | subpath={subpath} |
| 73 | entries={entries} |
| 74 | /> |
| 75 | {readmeHtml && ( |
| 76 | <div class="readme-section"> |
| 77 | <div class="readme-header"> |
| 78 | <span>README</span> |
| 79 | {readmePath && ( |
| 80 | <a |
| 81 | href={`/${repo.name}/raw/${treeRef}/${readmePath}`} |
| 82 | class="btn btn-sm" |
| 83 | > |
| 84 | Raw |
| 85 | </a> |
| 86 | )} |
| 87 | </div> |
| 88 | <div class="markdown-body">{readmeHtml}</div> |
| 89 | </div> |
| 90 | )} |
| 91 | </div> |
| 92 | </Layout> |
| 93 | ); |
| 94 | } |
| 95 |