// components/utilities/files/FilesTable.tsx "use client"; import { useMemo } from "react"; import { ArrowDownAZ, ArrowUpAZ, Download, Folder, FileText } from "lucide-react"; import { FsEntry, SortKey, SortDir, nicelyFormatBytes } from "./api"; export default function FilesTable({ entries, sortKey, sortDir, onSort, onOpen, onDownload, }: { entries: FsEntry[]; sortKey: SortKey; sortDir: SortDir; onSort: (k: SortKey) => void; onOpen: (entry: FsEntry) => void; onDownload: (entry: FsEntry) => void; }) { const sorted = useMemo(() => { const arr = [...entries]; const dir = sortDir === "asc" ? 1 : -1; arr.sort((a, b) => { // folders first if (a.isDir !== b.isDir) return a.isDir ? -1 : 1; switch (sortKey) { case "name": return a.name.localeCompare(b.name) * dir; case "size": return ((a.size ?? -1) - (b.size ?? -1)) * dir; case "modified": return (new Date(a.modified || 0).getTime() - new Date(b.modified || 0).getTime()) * dir; case "type": { const ax = ext(a.name), bx = ext(b.name); return ax.localeCompare(bx) * dir; } } }); return arr; }, [entries, sortKey, sortDir]); function ext(name: string) { const m = /\.([^.]+)$/.exec(name || ""); return m ? m[1].toLowerCase() : ""; } function SortBtn({ k, label }: { k: SortKey; label: string }) { const active = sortKey === k; return ( ); } return (
{sorted.map((e) => ( ))} {sorted.length === 0 && ( )}
Get
onOpen(e)} title="Double-click to open" > {e.isDir ? : } {e.name} {e.isDir ? "Folder" : (e.mime || ext(e.name).toUpperCase() || "File")} {e.isDir ? "—" : nicelyFormatBytes(e.size)} {e.modified ? new Date(e.modified).toLocaleString() : "—"} {!e.isDir && (
)}
Empty folder.
); }