"use client"; import { useState, useEffect } from "react"; import { useSearchParams } from "next/navigation"; import { FileText, Search } from "lucide-react"; import { useBills } from "@/lib/hooks/useBills"; import { BillCard } from "@/components/shared/BillCard"; import { TOPICS } from "@/lib/topics"; const CHAMBERS = ["", "House", "Senate"]; export default function BillsPage() { const searchParams = useSearchParams(); const [q, setQ] = useState(searchParams.get("q") ?? ""); const [chamber, setChamber] = useState(searchParams.get("chamber") ?? ""); const [topic, setTopic] = useState(searchParams.get("topic") ?? ""); const [hasText, setHasText] = useState(true); const [page, setPage] = useState(1); // Sync URL params → state so tag/topic links work when already on this page useEffect(() => { setQ(searchParams.get("q") ?? ""); setChamber(searchParams.get("chamber") ?? ""); setTopic(searchParams.get("topic") ?? ""); setPage(1); }, [searchParams]); const params = { ...(q && { q }), ...(chamber && { chamber }), ...(topic && { topic }), ...(hasText && { has_document: true }), page, per_page: 20, sort: "latest_action_date", }; const { data, isLoading } = useBills(params); return (

Bills

Browse and search US Congressional legislation

{/* Filters */}
{ setQ(e.target.value); setPage(1); }} className="w-full pl-9 pr-3 py-2 text-sm bg-card border border-border rounded-md focus:outline-none focus:ring-1 focus:ring-primary" />
{/* Results */} {isLoading ? (
Loading bills...
) : ( <>
{data?.total ?? 0} bills found Page {data?.page} of {data?.pages}
{data?.items?.map((bill) => ( ))}
{/* Pagination */} {data && data.pages > 1 && (
)} )}
); }