← back to Professional Directory
agents/web-agent/app/search/page.tsx
57 lines
// /search?q=... — search across professionals + organizations via pd-api /search.
const PD_API = process.env.PD_API_BASE || 'http://127.0.0.1:9874';
async function search(q: string) {
if (!q || q.length < 2) return { count: 0, rows: [] };
try {
const r = await fetch(`${PD_API}/search?q=${encodeURIComponent(q)}&limit=60`, { next: { revalidate: 60 } });
if (!r.ok) return { count: 0, rows: [] };
return await r.json();
} catch { return { count: 0, rows: [] }; }
}
export default async function SearchPage({ searchParams }: { searchParams: { q?: string } }) {
const q = String(searchParams?.q || '');
const out = await search(q);
const rows: any[] = out.rows || [];
return (
<section className="section">
<div className="eyebrow">Search</div>
<h2>{q ? `Results for "${q}"` : 'Search'}</h2>
<form action="/search" method="GET" className="search-shell" style={{ marginBottom: 32, marginLeft: 0, marginRight: 0 }}>
<input type="text" name="q" placeholder="Doctor, specialty, city, or practice name" defaultValue={q} />
<button type="submit">Search</button>
</form>
{q.length < 2 ? (
<p style={{ color: 'var(--ink-soft)' }}>Type a name, specialty, or ZIP to search.</p>
) : rows.length === 0 ? (
<p style={{ color: 'var(--ink-soft)' }}>No matches for "{q}".</p>
) : (
<>
<p style={{ color: 'var(--ink-soft)', marginTop: 0, marginBottom: 22 }}>{out.count} results</p>
<div className="dense-grid">
{rows.map((r) => {
const isPro = r.kind === 'professional';
const href = isPro ? `/doctors/${r.id}` : `/orgs/${r.id}`;
return (
<a key={`${r.kind}-${r.id}`} className="card" href={href}>
<span className="badge">{isPro ? 'Doctor' : 'Practice'}</span>
<span className="name">{titleCase(r.name)}</span>
<span className="meta">{r.detail || ''}</span>
</a>
);
})}
</div>
</>
)}
</section>
);
}
function titleCase(s: string) {
return String(s || '').toLowerCase().replace(/\b\w/g, c => c.toUpperCase());
}