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 | } |
| 19 | |
| 20 | export function FileTree({ |
| 21 | user, |
| 22 | repo, |
| 23 | ref: treeRef, |
| 24 | subpath, |
| 25 | entries, |
| 26 | branches, |
| 27 | readmeHtml, |
| 28 | }: FileTreeProps) { |
| 29 | const parts = subpath ? subpath.split("/") : []; |
| 30 | return ( |
| 31 | <Layout |
| 32 | user={user} |
| 33 | title={`${repo.name}${subpath ? `/${subpath}` : ""}`} |
| 34 | > |
| 35 | <div class="container"> |
| 36 | <RepoHeader repo={repo} /> |
| 37 | <RepoNav repo={repo} active="code" user={user} /> |
| 38 | <div class="tree-toolbar"> |
| 39 | <BranchSelector |
| 40 | repoName={repo.name} |
| 41 | branches={branches} |
| 42 | currentRef={treeRef} |
| 43 | view="tree" |
| 44 | path={subpath} |
| 45 | /> |
| 46 | </div> |
| 47 | {subpath && ( |
| 48 | <div class="breadcrumb"> |
| 49 | <a href={`/${repo.name}/tree/${treeRef}`}> |
| 50 | {repo.name} |
| 51 | </a> |
| 52 | {parts.map((part, i) => { |
| 53 | const partPath = parts.slice(0, i + 1).join("/"); |
| 54 | return ( |
| 55 | <> |
| 56 | <span class="breadcrumb-sep">/</span> |
| 57 | <a |
| 58 | href={`/${repo.name}/tree/${treeRef}/${partPath}`} |
| 59 | > |
| 60 | {part} |
| 61 | </a> |
| 62 | </> |
| 63 | ); |
| 64 | })} |
| 65 | </div> |
| 66 | )} |
| 67 | <FileTreeTable |
| 68 | repoName={repo.name} |
| 69 | treeRef={treeRef} |
| 70 | subpath={subpath} |
| 71 | entries={entries} |
| 72 | /> |
| 73 | {readmeHtml && ( |
| 74 | <div class="readme-section"> |
| 75 | <div class="readme-header">README</div> |
| 76 | <div class="markdown-body">{readmeHtml}</div> |
| 77 | </div> |
| 78 | )} |
| 79 | </div> |
| 80 | </Layout> |
| 81 | ); |
| 82 | } |
| 83 |