|
| 1 | +import Link from "next/link"; |
| 2 | +import { ChevronDown, ChevronUp } from "lucide-react"; |
| 3 | +import { formatEther } from "viem"; |
| 4 | + |
| 5 | +import { cn } from "@ark-market/ui"; |
| 6 | +import { Avatar, AvatarFallback, AvatarImage } from "@ark-market/ui/avatar"; |
| 7 | +import { Button } from "@ark-market/ui/button"; |
| 8 | +import { |
| 9 | + Table, |
| 10 | + TableBody, |
| 11 | + TableCell, |
| 12 | + TableHead, |
| 13 | + TableHeader, |
| 14 | + TableRow, |
| 15 | +} from "@ark-market/ui/table"; |
| 16 | + |
| 17 | +import type { |
| 18 | + CollectionSortBy, |
| 19 | + CollectionSortDirection, |
| 20 | + CollectionStats, |
| 21 | +} from "~/types"; |
| 22 | + |
| 23 | +function SortButton({ |
| 24 | + isActive, |
| 25 | + label, |
| 26 | + sortBy, |
| 27 | + sortDirection, |
| 28 | + onChange, |
| 29 | +}: { |
| 30 | + isActive: boolean; |
| 31 | + label?: string; |
| 32 | + sortBy: CollectionSortBy; |
| 33 | + sortDirection: CollectionSortDirection; |
| 34 | + onChange: (by: CollectionSortBy, direction: CollectionSortDirection) => void; |
| 35 | +}) { |
| 36 | + return ( |
| 37 | + <Button |
| 38 | + variant="unstyled" |
| 39 | + className="p-0" |
| 40 | + onClick={() => |
| 41 | + onChange( |
| 42 | + sortBy, |
| 43 | + isActive ? (sortDirection === "asc" ? "desc" : "asc") : "desc", |
| 44 | + ) |
| 45 | + } |
| 46 | + > |
| 47 | + {label ?? sortBy} |
| 48 | + <div className="flex flex-col"> |
| 49 | + <ChevronUp |
| 50 | + className={cn( |
| 51 | + "-mb-1 size-3", |
| 52 | + isActive && sortDirection === "asc" && "text-primary", |
| 53 | + )} |
| 54 | + /> |
| 55 | + <ChevronDown |
| 56 | + className={cn( |
| 57 | + "-mb-1 size-3", |
| 58 | + isActive && sortDirection === "desc" && "text-primary", |
| 59 | + )} |
| 60 | + /> |
| 61 | + </div> |
| 62 | + </Button> |
| 63 | + ); |
| 64 | +} |
| 65 | + |
| 66 | +interface CollectionsListProps { |
| 67 | + items: CollectionStats[] | null | undefined; |
| 68 | + sortBy: CollectionSortBy; |
| 69 | + sortDirection: CollectionSortDirection; |
| 70 | + onSortChange: ( |
| 71 | + sortBy: CollectionSortBy, |
| 72 | + sortDirection: CollectionSortDirection, |
| 73 | + ) => void; |
| 74 | +} |
| 75 | + |
| 76 | +export default function CollectionsList({ |
| 77 | + items, |
| 78 | + sortBy, |
| 79 | + sortDirection, |
| 80 | + onSortChange, |
| 81 | +}: CollectionsListProps) { |
| 82 | + return ( |
| 83 | + <div className="min-h-[800px]"> |
| 84 | + <Table className="pb-10"> |
| 85 | + <TableHeader className=""> |
| 86 | + <TableRow className=""> |
| 87 | + <TableHead className="sticky w-[250px] pl-6">Name</TableHead> |
| 88 | + <TableHead className=""> |
| 89 | + <SortButton |
| 90 | + onChange={onSortChange} |
| 91 | + sortBy="floor_price" |
| 92 | + sortDirection={sortDirection} |
| 93 | + isActive={sortBy === "floor_price"} |
| 94 | + label="Floor" |
| 95 | + /> |
| 96 | + </TableHead> |
| 97 | + <TableHead className=""> |
| 98 | + <SortButton |
| 99 | + onChange={onSortChange} |
| 100 | + sortBy="volume" |
| 101 | + sortDirection={sortDirection} |
| 102 | + isActive={sortBy === "volume"} |
| 103 | + label="Volume" |
| 104 | + /> |
| 105 | + </TableHead> |
| 106 | + <TableHead className=""> |
| 107 | + <SortButton |
| 108 | + onChange={onSortChange} |
| 109 | + sortBy="marketcap" |
| 110 | + sortDirection={sortDirection} |
| 111 | + isActive={sortBy === "marketcap"} |
| 112 | + label="Marketcap" |
| 113 | + /> |
| 114 | + </TableHead> |
| 115 | + <TableHead className=""> |
| 116 | + <SortButton |
| 117 | + onChange={onSortChange} |
| 118 | + sortBy="floor_percentage" |
| 119 | + sortDirection={sortDirection} |
| 120 | + isActive={sortBy === "floor_percentage"} |
| 121 | + label="Floor %" |
| 122 | + /> |
| 123 | + </TableHead> |
| 124 | + <TableHead className=""> |
| 125 | + <SortButton |
| 126 | + onChange={onSortChange} |
| 127 | + sortBy="top_bid" |
| 128 | + sortDirection={sortDirection} |
| 129 | + isActive={sortBy === "top_bid"} |
| 130 | + label="Top Bid" |
| 131 | + /> |
| 132 | + </TableHead> |
| 133 | + <TableHead className=""> |
| 134 | + <SortButton |
| 135 | + onChange={onSortChange} |
| 136 | + sortBy="number_of_sales" |
| 137 | + sortDirection={sortDirection} |
| 138 | + isActive={sortBy === "number_of_sales"} |
| 139 | + label="Sales" |
| 140 | + /> |
| 141 | + </TableHead> |
| 142 | + <TableHead className="">Listed</TableHead> |
| 143 | + </TableRow> |
| 144 | + </TableHeader> |
| 145 | + <TableBody className="font-numbers"> |
| 146 | + {items?.map((item) => ( |
| 147 | + <TableRow key={item.address} className=""> |
| 148 | + <TableCell className="flex w-[200px] items-center gap-2 pl-6"> |
| 149 | + <Link |
| 150 | + href={`/collection/${item.address}`} |
| 151 | + className="flex items-center gap-2" |
| 152 | + > |
| 153 | + <Avatar> |
| 154 | + <AvatarImage src={item.image} /> |
| 155 | + <AvatarFallback>{item.name.substring(0, 2)}</AvatarFallback> |
| 156 | + </Avatar> |
| 157 | + <div className="text-primary">{item.name}</div> |
| 158 | + </Link> |
| 159 | + </TableCell> |
| 160 | + <TableCell className="sticky"> |
| 161 | + {formatEther(BigInt(item.floor))}{" "} |
| 162 | + <span className="text-muted-foreground">ETH</span> |
| 163 | + </TableCell> |
| 164 | + <TableCell> |
| 165 | + {item.marketcap.toLocaleString()}{" "} |
| 166 | + <span className="text-muted-foreground">ETH</span> |
| 167 | + </TableCell> |
| 168 | + <TableCell>{item.floor_percentage}%</TableCell> |
| 169 | + <TableCell> |
| 170 | + {item.top_offer}{" "} |
| 171 | + <span className="text-muted-foreground">ETH</span> |
| 172 | + </TableCell> |
| 173 | + <TableCell> |
| 174 | + {item.volume} <span className="text-muted-foreground">ETH</span> |
| 175 | + </TableCell> |
| 176 | + <TableCell>{item.sales}</TableCell> |
| 177 | + <TableCell>{item.listed_items}</TableCell> |
| 178 | + </TableRow> |
| 179 | + ))} |
| 180 | + </TableBody> |
| 181 | + </Table> |
| 182 | + </div> |
| 183 | + ); |
| 184 | +} |
0 commit comments