import type { TreeEntry } from "../../services/git.ts"; interface FileTreeTableProps { repoName: string; treeRef: string; subpath: string; entries: TreeEntry[]; } export function FileTreeTable({ repoName, treeRef, subpath, entries, }: FileTreeTableProps) { const parts = subpath ? subpath.split("/") : []; const parentPath = parts.slice(0, -1).join("/"); const parentHref = parentPath ? `/${repoName}/tree/${treeRef}/${parentPath}` : `/${repoName}/tree/${treeRef}`; const sorted = [...entries].sort((a, b) => { if (a.type !== b.type) return a.type === "tree" ? -1 : 1; return a.name.localeCompare(b.name); }); return ( {subpath && ( )} {sorted.map((entry) => { const entryPath = subpath ? `${subpath}/${entry.name}` : entry.name; const href = entry.type === "tree" ? `/${repoName}/tree/${treeRef}/${entryPath}` : `/${repoName}/blob/${treeRef}/${entryPath}`; return ( ); })}
{DirIcon()} ..
{entry.type === "tree" ? DirIcon() : FileIcon()} {entry.name} {entry.type === "blob" && entry.size !== "-" ? formatSize(parseInt(entry.size, 10)) : ""}
); } function formatSize(bytes: number): string { if (bytes < 1024) return `${bytes} B`; if (bytes < 1024 * 1024) return `${(bytes / 1024).toFixed(1)} KB`; return `${(bytes / 1024 / 1024).toFixed(1)} MB`; } function DirIcon(): JSX.Element { return ``; } function FileIcon(): JSX.Element { return ``; }