import { useState } from 'react' import { Link } from 'react-router-dom' import { ImageOff, Plus } from 'lucide-react' import { useApi } from '../../hooks/useApi' import { EmptyBlock, ErrorBlock, LoadingBlock } from '../components/feedback' import { aInput, Btn, fmtDay, PageHeader, Pagination, Pill } from '../components/kit' const PAGE_SIZE = 20 export default function ProjectsPage() { const [filters, setFilters] = useState({ search: '', category: '', is_published: '' }) const [page, setPage] = useState(1) const params = Object.fromEntries(Object.entries({ ...filters, page, page_size: PAGE_SIZE }).filter(([, v]) => v !== '')) const { data, loading, error, reload } = useApi('/admin/projects', { params }) const set = (k) => (e) => { setFilters((f) => ({ ...f, [k]: e.target.value })) setPage(1) } return ( <> Add project} />
{loading && !data ? ( ) : error ? ( ) : data.items.length === 0 ? ( Add project} /> ) : (
    {data.items.map((p) => (
  • {p.featured_image ? ( ) : (
    )} {p.is_published ? 'Published' : 'Draft'} {p.images.length} photo{p.images.length === 1 ? '' : 's'}

    {p.title}

    {p.category}{p.capacity_kw ? ` · ${p.capacity_kw} kW` : ''}{p.location ? ` · ${p.location}` : ''}

    Installed {fmtDay(p.installation_date)}

  • ))}
)} {data && } ) }