import { Combobox, ComboboxItem, ComboboxProvider, VisuallyHidden } from '@ariakit/react' import { MagnifyingGlassIcon } from '@heroicons/react/20/solid' import { Hit } from 'instantsearch.js' import { SendEventForHits } from 'instantsearch.js/es/lib/utils' import Link from 'next/link' import { usePathname, useRouter } from 'next/navigation' import { Dialog as _Dialog } from 'radix-ui' import { Fragment, startTransition, useState } from 'react' import { Highlight } from 'react-instantsearch' import { twJoin } from 'tailwind-merge' import { SearchEntry } from '@/utils/algolia' import { ContentHighlight } from './ContentHighlight' interface AutocompleteProps { items: Hit[] onChange(value: string): void onInputChange(value: string): void onClose(): void sendEvent: SendEventForHits } export default function SearchDialog({ items, onInputChange, onChange, onClose, sendEvent, }: AutocompleteProps) { const [open, setOpen] = useState(true) const [value, setValue] = useState('') const handleOpenChange = (open: boolean) => { if (!open) { onClose() } setOpen(open) } return ( defaultSelectedValue="" open={open} setOpen={setOpen} resetValueOnHide includesBaseElement={false} setValue={(newValue) => { startTransition(() => { setValue(newValue) onInputChange(newValue) }) }} setSelectedValue={(newValue) => onChange(newValue)} >
) } function SearchInput({ value }: { value: string }) { const router = useRouter() const pathName = usePathname() const handleKeyDown = (e: React.KeyboardEvent) => { if (e.key !== 'Enter') return const searchPath = pathName.startsWith('/blog') ? '/search/blog' : '/search' router.push(`${searchPath}?query=${encodeURIComponent(value.trim())}`) } return (
) } function Results({ items, sendEvent }: { items: Hit[]; sendEvent: SendEventForHits }) { let section = '' const renderedItems = items.map((hit) => { const showChapter = hit.section !== section section = hit.section const href = hit.headingSlug ? `${hit.path}#${hit.headingSlug}` : hit.path return ( {showChapter && (
{section}
)} { if (e.key === 'Enter') { sendEvent('click', hit, 'Hit clicked via keyboard') } }} > sendEvent('click', hit, 'Hit clicked')}>
) }) return (
{items.length === 0 && (

No results found.

Will you tell us what you{"'"}re looking for on our{' '} discord ?

)} {items.length !== 0 && renderedItems}
) } function SearchDialogWrapper({ children, onOpenChange, }: { children: React.ReactNode onOpenChange(open: boolean): void }) { return ( <_Dialog.Root open onOpenChange={onOpenChange}> <_Dialog.Portal> <_Dialog.Overlay /> <_Dialog.Content className="fixed inset-0 z-50" style={{ pointerEvents: 'none' }}> <_Dialog.Title>Search <_Dialog.Description>Search dialog {children} ) }