UI/UX: - Bill detail page tab UI (Analysis / Timeline / Votes / Notes) - Topic tag pills on bill detail and listing pages — filtered to known topics, clickable, properly labelled via shared lib/topics.ts - Notes panel always-open in Notes tab; sign-in prompt for guests - Collapsible sidebar with icon-only mode and localStorage persistence - Bills page defaults to has-text filter enabled - Follow mode dropdown transparency fix - Favicon (Landmark icon, blue background) Security: - Fernet encryption for ntfy passwords at rest (app/core/crypto.py) - Separate ENCRYPTION_SECRET_KEY env var; falls back to JWT derivation - ntfy_password no longer returned in GET response — replaced with ntfy_password_set: bool; NotificationSettingsUpdate type for writes - JWT_SECRET_KEY fail-fast on startup if using default placeholder - get_optional_user catches (JWTError, ValueError) only, not Exception Bug fixes & code quality: - Dashboard N+1 topic query replaced with single OR query - notification_utils.py topic follower N+1 replaced with batch query - Note query in bill detail page gated on token (enabled: !!token) - search.py max_length=500 guard against oversized queries - CollectionCreate.validate_name wired up with @field_validator - LLM_RATE_LIMIT_RPM default raised from 10 to 50 Authored by: Jack Levy
129 lines
4.7 KiB
TypeScript
129 lines
4.7 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";
|
|
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 (
|
|
<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.map((t) => <option key={t.tag} value={t.tag}>{t.label}</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>
|
|
);
|
|
}
|