ZIP lookup (GET /api/members/by-zip/{zip}):
- Two-step geocoding: Nominatim (ZIP → lat/lng) then Census TIGERweb
Legislative identify (lat/lng → congressional district via GEOID)
- Handles at-large states (AK, DE, MT, ND, SD, VT, WY)
- Added rep_lookup health check to admin External API Health panel
congress_api.py fixes:
- parse_member_from_api: normalize state full name → 2-letter code
(Congress.gov returns "Florida", DB expects "FL")
- parse_member_from_api: read district from top-level data field,
not current_term (district is not inside the term object)
Celery beat: schedule sync_members daily at 1 AM UTC so chamber,
district, and contact info stay current without manual triggering
Members page redesign: photo avatars, party/state/chamber chips,
phone + website links, ZIP lookup form to find your reps
Draft letter improvements: pass rep_name from ZIP lookup so letter
opens with "Dear Representative Franklin," instead of generic salutation;
add has_document filter to bills list endpoint
UX additions: HelpTip component, How It Works page, "How it works"
sidebar nav link, collections page description copy
Authored-By: Jack Levy
134 lines
4.9 KiB
TypeScript
134 lines
4.9 KiB
TypeScript
"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";
|
|
|
|
const CHAMBERS = ["", "House", "Senate"];
|
|
const TOPICS = [
|
|
"", "healthcare", "taxation", "defense", "education", "immigration",
|
|
"environment", "housing", "infrastructure", "technology", "agriculture",
|
|
"judiciary", "foreign-policy", "veterans", "social-security", "trade",
|
|
"budget", "energy", "banking", "transportation", "labor",
|
|
];
|
|
|
|
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(false);
|
|
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 (
|
|
<div className="space-y-6">
|
|
<div>
|
|
<h1 className="text-2xl font-bold">Bills</h1>
|
|
<p className="text-muted-foreground text-sm mt-1">Browse and search US Congressional legislation</p>
|
|
</div>
|
|
|
|
{/* Filters */}
|
|
<div className="flex gap-3 flex-wrap">
|
|
<div className="relative flex-1 min-w-48">
|
|
<Search className="absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-muted-foreground" />
|
|
<input
|
|
type="text"
|
|
placeholder="Search bills..."
|
|
value={q}
|
|
onChange={(e) => { 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"
|
|
/>
|
|
</div>
|
|
<select
|
|
value={chamber}
|
|
onChange={(e) => { setChamber(e.target.value); setPage(1); }}
|
|
className="px-3 py-2 text-sm bg-card border border-border rounded-md focus:outline-none"
|
|
>
|
|
<option value="">All Chambers</option>
|
|
{CHAMBERS.slice(1).map((c) => <option key={c} value={c}>{c}</option>)}
|
|
</select>
|
|
<select
|
|
value={topic}
|
|
onChange={(e) => { setTopic(e.target.value); setPage(1); }}
|
|
className="px-3 py-2 text-sm bg-card border border-border rounded-md focus:outline-none"
|
|
>
|
|
<option value="">All Topics</option>
|
|
{TOPICS.slice(1).map((t) => <option key={t} value={t}>{t}</option>)}
|
|
</select>
|
|
<button
|
|
onClick={() => { setHasText((v) => !v); setPage(1); }}
|
|
className={`flex items-center gap-1.5 px-3 py-2 text-sm rounded-md border transition-colors ${
|
|
hasText
|
|
? "bg-primary text-primary-foreground border-primary"
|
|
: "bg-card border-border text-muted-foreground hover:bg-accent hover:text-foreground"
|
|
}`}
|
|
title="Show only bills with published text"
|
|
>
|
|
<FileText className="w-3.5 h-3.5" />
|
|
Has text
|
|
</button>
|
|
</div>
|
|
|
|
{/* Results */}
|
|
{isLoading ? (
|
|
<div className="text-center py-20 text-muted-foreground">Loading bills...</div>
|
|
) : (
|
|
<>
|
|
<div className="flex items-center justify-between text-sm text-muted-foreground">
|
|
<span>{data?.total ?? 0} bills found</span>
|
|
<span>Page {data?.page} of {data?.pages}</span>
|
|
</div>
|
|
|
|
<div className="space-y-3">
|
|
{data?.items?.map((bill) => (
|
|
<BillCard key={bill.bill_id} bill={bill} />
|
|
))}
|
|
</div>
|
|
|
|
{/* Pagination */}
|
|
{data && data.pages > 1 && (
|
|
<div className="flex justify-center gap-2">
|
|
<button
|
|
onClick={() => setPage((p) => Math.max(1, p - 1))}
|
|
disabled={page === 1}
|
|
className="px-4 py-2 text-sm bg-card border border-border rounded-md disabled:opacity-40 hover:bg-accent transition-colors"
|
|
>
|
|
Previous
|
|
</button>
|
|
<button
|
|
onClick={() => setPage((p) => Math.min(data.pages, p + 1))}
|
|
disabled={page === data.pages}
|
|
className="px-4 py-2 text-sm bg-card border border-border rounded-md disabled:opacity-40 hover:bg-accent transition-colors"
|
|
>
|
|
Next
|
|
</button>
|
|
</div>
|
|
)}
|
|
</>
|
|
)}
|
|
</div>
|
|
);
|
|
}
|