import { Link } from "@tanstack/react-router"; import { CommitAuthor } from "./CommitAuthor"; import { Markdown } from "~/ui/Markdown"; import { Panel } from "~/ui/Panel"; import { RelativeTime } from "~/ui/RelativeTime"; import { StatusDot } from "~/ui/StatusDot"; import { SkeletonLine } from "@cloudflare/kumo/components/loader"; import { ArrowBendLeftUpIcon, BookOpenTextIcon, FileIcon, FolderSimpleIcon, type Icon as PhosphorIcon, LinkSimpleIcon, PackageIcon, TerminalWindowIcon, } from "@phosphor-icons/react"; import { TreeToolbar } from "./TreeToolbar"; import { useLastCommits } from "~/hooks/use-last-commits"; import type { CommitSummary, StatusState, TreeEntry } from "~/lib/types"; import type { CommitBrief } from "~/lib/code-intel"; type Props = { owner: string; repo: string; gitRef: { kind: string; name: string; sha: string }; path: string; entries: TreeEntry[]; commit: CommitSummary & { authorAccount: string | null }; commitStatus: StatusState | null; /** Latest workflow run for the commit; the status dot links to it, else to the commit's checks. */ commitRun: number | null; readme: { path: string; html: string | null; text: string | null } | null; branches: string[]; tags: string[]; canWrite: boolean; /** The viewer may boot editor containers here (write access, containers on, plan includes them). */ containersAllowed: boolean; }; const SKELETON_FIXED = { minWidth: 100, maxWidth: 100, minDuration: 1.5, maxDuration: 1.5, minDelay: 0, maxDelay: 0 }; function EntryCommit({ commit }: { commit: CommitBrief | null | undefined }) { if (commit === undefined) return ; if (commit === null) return null; return ( {commit.subject} ); } function CommitStatusLink({ owner, repo, sha, state, run, }: { owner: string; repo: string; sha: string; state: StatusState | null; run: number | null; }) { if (!state) return null; const className = "flex rounded-full"; if (run === null) { return ( ); } return ( ); } const ICONS: Record = { tree: FolderSimpleIcon, blob: FileIcon, exec: TerminalWindowIcon, symlink: LinkSimpleIcon, gitlink: PackageIcon, }; function EntryIcon({ type }: { type: TreeEntry["type"] }) { const EntryGlyph = ICONS[type]; const isDir = type === "tree"; return ( ); } export function TreeView({ owner, repo, gitRef, path, entries, commit, commitStatus, commitRun, readme, branches, tags, canWrite, containersAllowed, }: Props) { const parent = path.split("/").slice(0, -1).join("/"); const lastCommits = useLastCommits(owner, repo, gitRef.sha, path); return ( {commit.subject} } actions={ {commit.shortSha} {" "} ยท } > {path && ( .. )} {entries.map((entry) => ( {entry.name} ))} {readme && ( {readme.path} } > {readme.html !== null ? ( ) : ( {readme.text} )} )} ); }
{readme.text}