"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 (
No results found for “{query}”
Try different keywords or check the spelling.
{total} result{total !== 1 ? "s" : ""} for “{query}”
{result.entityType}