import { useState } from "react"; import { Link } from "react-router-dom"; import type { PageSummary } from "@ledger/shared"; import { EmptyState } from "./EmptyState"; import { Icon } from "./Icon"; import { PageHeader } from "./PageHeader"; import { SearchBar } from "./SearchBar"; type Space = { id: string; name: string; key: string; visibility: string; }; export function SearchPage({ spaces, results, isLoading, onSearch }: { spaces: Space[]; results: PageSummary[]; isLoading: boolean; onSearch: (query: string) => Promise; }) { const [query, setQuery] = useState(""); async function handleSearch(nextQuery: string) { setQuery(nextQuery); await onSearch(nextQuery); } return (

Results

{query ? `Results for "${query}"` : "Search results"}

{isLoading ?

Searching documentation...

: null} {!isLoading && query && results.length === 0 ? ( ) : null} {!isLoading && !query ? ( ) : null} {!isLoading && results.length > 0 ? (
{results.map((page) => (
{page.title}

{spaces.find((space) => space.id === page.spaceId)?.name ?? "Collection"} - {page.visibility}

{page.excerpt ?? "Open this page to read more."}

))}
) : null}
); }