import { Group, Center, Text } from "@mantine/core"; import { Spotlight } from "@mantine/spotlight"; import { IconFileDescription, IconSearch } from "@tabler/icons-react"; import React, { useState } from "react"; import { useNavigate } from "react-router-dom"; import { useDebouncedValue } from "@mantine/hooks"; import { usePageSearchQuery } from "@/features/search/queries/search-query"; import { buildPageUrl } from "@/features/page/page.utils.ts"; interface SearchSpotlightProps { spaceId?: string; } export function SearchSpotlight({ spaceId }: SearchSpotlightProps) { const navigate = useNavigate(); const [query, setQuery] = useState(""); const [debouncedSearchQuery] = useDebouncedValue(query, 300); const { data: searchResults, isLoading, error, } = usePageSearchQuery({ query: debouncedSearchQuery, spaceId }); const pages = ( searchResults && searchResults.length > 0 ? searchResults : [] ).map((page) => ( navigate(buildPageUrl(page.space.slug, page.slugId, page.title)) } >
{page?.icon ? ( {page.icon} ) : ( )}
{page.title} {page?.highlight && ( )}
)); return ( <> } /> {query.length === 0 && pages.length === 0 && ( Start typing to search... )} {query.length > 0 && pages.length === 0 && ( No results found... )} {pages.length > 0 && pages} ); }