import { useMemo, useState } from "react" import { ArrowDown, ArrowUp, Search } from "lucide-react" import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from "@/components/ui/table" import { Input } from "@/components/ui/input" import { Button } from "@/components/ui/button" import { REL_NAME, type Author, type Repo } from "@/lib/types" import { num as fmt, hfUrl } from "@/lib/format" import { RelDot } from "@/components/rel" import { Who } from "@/components/who" type Key = "id" | "rel" | "dl30" | "dlall" | "d1" export function ModelTable({ repos, authors, hasDaily }: { repos: Repo[]; authors: Record; hasDaily: boolean }) { const [q, setQ] = useState("") const [sort, setSort] = useState<{ k: Key; dir: 1 | -1 }>({ k: "dl30", dir: -1 }) const [shown, setShown] = useState(20) const rows = useMemo(() => { const s = q.trim().toLowerCase() const list = s ? repos.filter((r) => r.id.toLowerCase().includes(s)) : repos return [...list].sort((a, b) => { const x = a[sort.k], y = b[sort.k] if (x == null || y == null) return (x == null ? 1 : 0) - (y == null ? 1 : 0) return (x < y ? -1 : x > y ? 1 : 0) * sort.dir }) }, [repos, q, sort]) const cols: [Key, string, boolean][] = [ ["id", "Model", false], ["rel", "Type", false], ["dl30", "30 days", true], ["dlall", "All-time", true], ...(hasDaily ? ([["d1", "Last day", true]] as [Key, string, boolean][]) : []), ] const head = (k: Key, label: string, num: boolean) => ( ) return (
{ setQ(e.target.value); setShown(20) }} placeholder="Search models or builders" className="h-11 rounded-full pl-10 text-[15px]" aria-label="Search models or builders" />
{cols.map(([k, l, n]) => head(k, l, n))} {rows.slice(0, shown).map((r) => { const [owner, name] = r.id.split("/") return ( {owner}/{name} {REL_NAME[r.rel]} {fmt(r.dl30)} {fmt(r.dlall)} {hasDaily && {fmt(r.d1)}} ) })}
{rows.length > shown && (
)}
) }