'use client' import { useState } from 'react' import { useRouter } from 'next/navigation' import { useWallet } from '@solana/connector/react' import { useMyListings } from '@/hooks/useMyListings' import { useMyOrders } from '@/hooks/useMyOrders' import { Badge, STATUS_COLORS } from '@/components/ui/Badge' import { Button } from '@/components/ui/Button' import { abbrev, fmtSol } from '@/lib/format' export function Dashboard() { const router = useRouter() const { account } = useWallet() const [tab, setTab] = useState<'listings' | 'orders'>('listings') const { data: myListings = [], isLoading: loadingL } = useMyListings() const { data: myOrders = [], isLoading: loadingO } = useMyOrders() if (!account) { return (

Wallet required

Connect a wallet to view your listings and orders.

) } return (

My Dashboard

{abbrev(account)}

{( [ { key: 'listings' as const, label: `My Listings · ${myListings.length}` }, { key: 'orders' as const, label: `My Orders · ${myOrders.length}` }, ] as const ).map((t) => ( ))}
{tab === 'listings' && (
{loadingL && (
Loading…
)} {!loadingL && myListings.length === 0 && (
You have no listings yet.
)}
{myListings.map((l) => { const sc = STATUS_COLORS[l.data.isActive ? 'active' : 'inactive'] const avail = l.data.quantity - l.data.quantityReserved return (
router.push(`/listing/${l.address}`)} style={{ flex: 1, minWidth: 0, cursor: 'pointer' }} >
{l.data.name || `Listing #${String(l.data.listingId)}`} {l.data.isActive ? 'Active' : 'Inactive'}
{abbrev(l.address)} · {fmtSol(l.data.price)} · {avail}/ {String(l.data.quantity)} avail · {String(l.data.quantityReserved)} pending
) })}
)} {tab === 'orders' && (
{loadingO && (
Loading…
)} {!loadingO && myOrders.length === 0 && (
You have no orders as a buyer.
)}
{myOrders.map((o) => (
router.push(`/order/${o.address}`)} style={{ background: 'var(--bg2)', border: '1px solid var(--bd)', borderRadius: 'var(--radius)', padding: '18px 20px', display: 'flex', alignItems: 'center', gap: 18, cursor: 'pointer', }} >
{abbrev(o.data.listing)}
#{String(o.data.orderId)} · {fmtSol(o.data.amount)}
#{String(o.data.escrowId)}
))}
)}
) }