'use client' import { useState } from 'react' import { useRouter } from 'next/navigation' import { useListings } from '@/hooks/useListings' import { Badge, STATUS_COLORS } from '@/components/ui/Badge' import { abbrev, fmtSol, fmtTok } from '@/lib/format' import type { ListingAccountWithPda } from '@solisting/sdk' type Filter = 'all' | 'active' | 'inactive' function priceLabel(listing: ListingAccountWithPda['data']): string { const cur = listing.canonicalCurrency if (cur.__kind === 'Sol') return fmtSol(listing.price) return fmtTok(listing.price, cur.decimals, 'SPL') } export function ListingsTable() { const router = useRouter() const { data: listings = [], isLoading, error } = useListings() const [filter, setFilter] = useState('all') const [sellerFilter, setSellerFilter] = useState('') const rows = listings.filter((l) => { if (filter === 'active' && !l.data.isActive) return false if (filter === 'inactive' && l.data.isActive) return false if (sellerFilter && !l.data.seller.toLowerCase().includes(sellerFilter.toLowerCase())) return false return true }) if (isLoading) { return
Loading listings…
} if (error) { return
{String(error)}
} const FILTERS: { key: Filter; label: string }[] = [ { key: 'all', label: 'All' }, { key: 'active', label: 'Active' }, { key: 'inactive', label: 'Inactive' }, ] return (
{/* Header */}

Listings

{listings.length} ListingAccount PDAs · solisting program

setSellerFilter(e.target.value)} placeholder="Filter by seller address" style={{ height: 38, width: 220, padding: '0 13px', background: 'var(--bg3)', border: '1px solid var(--bd)', borderRadius: 10, fontSize: 13, fontFamily: 'var(--font-mono)', outline: 'none' }} />
{FILTERS.map((f) => { const active = filter === f.key return ( ) })}
{/* Table */}
LISTING
SELLER
PRICE
AVAIL / TOTAL
ORDERS
STATUS
{rows.length === 0 && (
No listings match these filters.
)} {rows.map((l) => { const avail = l.data.quantity - l.data.quantityReserved const statusKey = l.data.isActive ? 'active' : 'inactive' const sc = STATUS_COLORS[statusKey] return (
router.push(`/listing/${l.address}`)} style={{ display: 'grid', gridTemplateColumns: '2.4fr 1.1fr 1fr 1.1fr .8fr .9fr', gap: 14, padding: '15px 20px', borderBottom: '1px solid var(--bdSoft)', cursor: 'pointer', alignItems: 'center' }} >
{l.data.name || abbrev(l.address)}
#{String(l.data.listingId)} · {abbrev(l.address)}
{abbrev(l.data.seller)}
{priceLabel(l.data)}
{avail} / {l.data.quantity}
{l.data.quantityReserved}
{l.data.isActive ? 'Active' : 'Inactive'}
) })}
) }