feat: user search/discovery

Previously the only way to find someone to follow was knowing their
exact username. Add GET /api/v1/users/search (name/username ilike,
excludes blocked-either-way) and a /people page with debounced search
+ inline follow buttons. Linked from the Explore page.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
Arnaud
2026-07-03 22:12:03 +02:00
parent 57c29f62b4
commit 73a71d28cd
4 changed files with 149 additions and 1 deletions
@@ -244,7 +244,12 @@ export function ExplorePageContent({ trending, recent, initialQuery }: Props) {
<div className="max-w-5xl mx-auto space-y-10">
{/* Search bar */}
<div className="space-y-3">
<h1 className="text-3xl font-bold">{t("title")}</h1>
<div className="flex items-center justify-between">
<h1 className="text-3xl font-bold">{t("title")}</h1>
<Link href="/people" className="text-sm text-muted-foreground hover:text-foreground underline underline-offset-4">
Find people
</Link>
</div>
<form onSubmit={handleSubmit} className="relative">
<Search className="absolute left-3 top-1/2 -translate-y-1/2 h-5 w-5 text-muted-foreground pointer-events-none" />
<Input
@@ -0,0 +1,82 @@
"use client";
import { useEffect, useState } from "react";
import Link from "next/link";
import { Avatar, AvatarFallback, AvatarImage } from "@/components/ui/avatar";
import { Input } from "@/components/ui/input";
import { FollowButton } from "@/components/social/follow-button";
import { Search } from "lucide-react";
type PersonResult = {
id: string;
name: string;
username: string | null;
avatarUrl: string | null;
bio: string | null;
};
export function PeopleSearch() {
const [q, setQ] = useState("");
const [results, setResults] = useState<PersonResult[]>([]);
const [loading, setLoading] = useState(false);
useEffect(() => {
if (q.trim().length < 2) {
setResults([]);
return;
}
const timeout = setTimeout(async () => {
setLoading(true);
try {
const res = await fetch(`/api/v1/users/search?q=${encodeURIComponent(q.trim())}`);
if (res.ok) {
const data = (await res.json()) as { users: PersonResult[] };
setResults(data.users);
}
} finally {
setLoading(false);
}
}, 300);
return () => clearTimeout(timeout);
}, [q]);
return (
<div className="space-y-4">
<div className="relative">
<Search className="absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground" />
<Input
value={q}
onChange={(e) => setQ(e.target.value)}
placeholder="Search people by name or username…"
className="pl-9"
/>
</div>
{loading && <p className="text-sm text-muted-foreground">Searching</p>}
{!loading && q.trim().length >= 2 && results.length === 0 && (
<p className="text-sm text-muted-foreground">No one found.</p>
)}
<div className="space-y-2">
{results.map((person) => (
<div key={person.id} className="flex items-center gap-3 rounded-lg border p-3">
<Link href={`/u/${person.username}`} className="flex items-center gap-3 flex-1 min-w-0">
<Avatar className="h-10 w-10 shrink-0">
{person.avatarUrl && <AvatarImage src={person.avatarUrl} alt={person.name} />}
<AvatarFallback>{person.name.slice(0, 2).toUpperCase()}</AvatarFallback>
</Avatar>
<div className="min-w-0">
<p className="font-medium text-sm truncate">{person.name}</p>
<p className="text-xs text-muted-foreground truncate">@{person.username}</p>
</div>
</Link>
{person.username && (
<FollowButton targetUserId={person.id} targetUsername={person.username} />
)}
</div>
))}
</div>
</div>
);
}