"use client"; import { useSearchApi } from "./_hooks"; interface SearchResult { id: string; entityType: string; entityId: string; title: string; url: string; image?: string; score: number; } interface SearchResultsProps { query: string; entityType?: string | undefined; sessionId?: string | undefined; limit?: number | undefined; } export function SearchResults({ query, entityType, sessionId, limit = 20, }: SearchResultsProps) { const api = useSearchApi(); const { data, isLoading } = query.trim().length > 0 ? (api.search.useQuery({ q: query.trim(), type: entityType, limit: String(limit), sessionId, }) as { data: { results: SearchResult[]; total: number } | undefined; isLoading: boolean; }) : { data: undefined, isLoading: false }; const results = data?.results ?? []; const total = data?.total ?? 0; if (!query.trim()) return null; if (isLoading) { return (
{Array.from({ length: 4 }).map((_, i) => (
))}
); } if (results.length === 0) { return (

No results found for “{query}”

Try different keywords or check the spelling.

); } return (

{total} result{total !== 1 ? "s" : ""} for “{query}”

{results.map((result) => (
{result.image && ( )}

{result.title}

{result.entityType}

))}
); }