({
apiKey,
indexName = 'threads',
searchClient,
settings,
routing,
middlewares,
isSubDomainRouting,
}: {
apiKey: string;
indexName?: string;
searchClient: (apiKey: string) => any;
settings: Settings;
routing?: any;
middlewares?: any[];
isSubDomainRouting: boolean;
})
| 16 | import { Settings } from '@linen/types'; |
| 17 | |
| 18 | export function TypesenseSearch({ |
| 19 | apiKey, |
| 20 | indexName = 'threads', |
| 21 | searchClient, |
| 22 | settings, |
| 23 | routing, |
| 24 | middlewares, |
| 25 | isSubDomainRouting, |
| 26 | }: { |
| 27 | apiKey: string; |
| 28 | indexName?: string; |
| 29 | searchClient: (apiKey: string) => any; |
| 30 | settings: Settings; |
| 31 | routing?: any; |
| 32 | middlewares?: any[]; |
| 33 | isSubDomainRouting: boolean; |
| 34 | }) { |
| 35 | const [open, setOpen] = useState<boolean>(false); |
| 36 | |
| 37 | async function isSearchOngoing() { |
| 38 | try { |
| 39 | const url = new URL(window.location.toString()); |
| 40 | if (url.searchParams.has(`${indexName}[query]`)) { |
| 41 | setOpen(true); |
| 42 | } |
| 43 | } catch (error) {} |
| 44 | } |
| 45 | |
| 46 | useEffect(() => { |
| 47 | isSearchOngoing(); |
| 48 | }, []); |
| 49 | |
| 50 | return ( |
| 51 | <div className={styles.container} key={indexName + apiKey}> |
| 52 | <TextInput |
| 53 | className={styles.input} |
| 54 | id="search" |
| 55 | icon={<FiSearch />} |
| 56 | placeholder={'Search'} |
| 57 | type="search" |
| 58 | {...{ |
| 59 | onFocus: () => { |
| 60 | setOpen(true); |
| 61 | }, |
| 62 | }} |
| 63 | /> |
| 64 | <Modal open={open} close={() => setOpen(false)} size="xl"> |
| 65 | <InstantSearch |
| 66 | indexName={indexName} |
| 67 | searchClient={searchClient(apiKey)} |
| 68 | routing={routing} |
| 69 | > |
| 70 | {middlewares?.length && <Middleware middlewares={middlewares} />} |
| 71 | <div className={styles.searchBar}> |
| 72 | <SearchBox placeholder="Search" autoFocus /> |
| 73 | <div className={styles.x}> |
| 74 | <Icon onClick={() => setOpen(false)}> |
| 75 | <FiX /> |
nothing calls this directly
no test coverage detected