"use client"; import { useEffect, useState } from "react"; import Link from "next/link"; import { useTranslations } from "next-intl"; 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 t = useTranslations("people"); const [q, setQ] = useState(""); const [results, setResults] = useState([]); 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 (
setQ(e.target.value)} placeholder={t("searchPlaceholder")} className="pl-9" />
{loading &&

{t("searching")}

} {!loading && q.trim().length >= 2 && results.length === 0 && (

{t("noneFound")}

)}
{results.map((person) => (
{person.avatarUrl && } {person.name.slice(0, 2).toUpperCase()}

{person.name}

@{person.username}

{person.username && ( )}
))}
); }