"use client"; import Link from "next/link"; import { Folder, FileCode, FileText, FileJson, File } from "lucide-react"; type FileEntry = { name: string; type: "blob" | "tree"; oid: string; path: string; }; const FILE_ICONS: Record = { ts: FileCode, tsx: FileCode, js: FileCode, jsx: FileCode, py: FileCode, rb: FileCode, go: FileCode, rs: FileCode, java: FileCode, md: FileText, txt: FileText, json: FileJson, yaml: FileJson, yml: FileJson, }; function getFileIcon(name: string, type: "blob" | "tree") { if (type === "tree") return Folder; const ext = name.split(".").pop()?.toLowerCase() || ""; return FILE_ICONS[ext] || File; } export function FileTree({ files, username, repoName, branch }: { files: FileEntry[]; username: string; repoName: string; branch: string; basePath?: string }) { return (
{files.map((file) => { const Icon = getFileIcon(file.name, file.type); const href = file.type === "tree" ? `/${username}/${repoName}/tree/${branch}/${file.path}` : `/${username}/${repoName}/blob/${branch}/${file.path}`; return ( {file.name} ); })}
); }