import { Folder, File, ChevronRight, Loader2 } from "lucide-react"; import type { FileNode } from "../api"; interface FileBrowserProps { entries: FileNode[]; currentPath: string; onSelectFile: (path: string) => void; onNavigate: (path: string) => void; loading?: boolean; error?: string | null; onRetry?: () => void; } function formatBytes(bytes?: number): string { if (bytes === undefined) return ""; if (bytes < 1024) return `${bytes} B`; if (bytes < 1024 * 1024) return `${(bytes / 1024).toFixed(1)} KB`; return `${(bytes / (1024 * 1024)).toFixed(1)} MB`; } function formatTime(mtime?: string): string { if (!mtime) return ""; const date = new Date(mtime); return date.toLocaleDateString(); } export function FileBrowser({ entries, currentPath, onSelectFile, onNavigate, loading, error, onRetry, }: FileBrowserProps) { if (loading) { return (
Loading files...
); } if (error) { return (

Error: {error}

{onRetry && ( )}
); } return (
{currentPath !== "." && ( )} {currentPath === "." ? "Root" : currentPath}
{entries.length === 0 ? (
(empty directory)
) : ( entries.map((entry) => (
{ if (entry.type === "directory") { onNavigate(currentPath === "." ? entry.name : `${currentPath}/${entry.name}`); } else { onSelectFile(currentPath === "." ? entry.name : `${currentPath}/${entry.name}`); } }} >
{entry.type === "directory" ? ( ) : ( )}
{entry.name}
{entry.type === "file" && entry.size !== undefined && (
{formatBytes(entry.size)}
)} {entry.mtime && (
{formatTime(entry.mtime)}
)}
)) )}
); }