|
1 |
| -import { useSearch } from '@/hooks/useSearch/useSearch'; |
2 |
| -import { mapMatches } from '@/pages/api/semanticsearch'; |
3 |
| -import { analyticsEvent, EVENT_NAMES } from '@/utils/analytics'; |
| 1 | +import dynamic from 'next/dynamic'; |
4 | 2 | import type { FC } from 'react';
|
5 |
| -import React, { useEffect, useState } from 'react'; |
6 |
| -import { SearchResults } from './components/SearchResults'; |
7 |
| -import useAlgoliaSearch from './useAlgoliaSearch'; |
| 3 | +import React from 'react'; |
8 | 4 |
|
9 |
| -interface IProps { |
| 5 | +const SearchTab = dynamic(() => import('./SearchTab')); |
| 6 | + |
| 7 | +export interface ISearchProps { |
10 | 8 | query?: string;
|
11 | 9 | hasScroll?: boolean;
|
12 | 10 | limitResults?: number;
|
13 | 11 | }
|
14 | 12 |
|
15 |
| -export const Search: FC<IProps> = ({ query, hasScroll, limitResults }) => { |
16 |
| - const [tabName, setTabName] = useState<string | undefined>('docs'); |
17 |
| - const { metadata, handleSubmit, error, isLoading } = |
18 |
| - useAlgoliaSearch(limitResults); |
19 |
| - |
20 |
| - const { |
21 |
| - outputStream, |
22 |
| - conversation, |
23 |
| - error: conversationError, |
24 |
| - isLoading: conversationIsLoading, |
25 |
| - handleSubmit: handleConversationSubmit, |
26 |
| - } = useSearch(); |
27 |
| - |
28 |
| - const semanticResults = metadata?.map(mapMatches); |
29 |
| - |
30 |
| - useEffect(() => { |
31 |
| - if ( |
32 |
| - query !== undefined && |
33 |
| - query.trim() !== '' && |
34 |
| - tabName !== undefined && |
35 |
| - tabName.trim() !== '' |
36 |
| - ) { |
37 |
| - if (tabName === 'docs') { |
38 |
| - // eslint-disable-next-line @typescript-eslint/no-floating-promises |
39 |
| - handleSubmit(query); |
40 |
| - } else { |
41 |
| - // eslint-disable-next-line @typescript-eslint/no-floating-promises |
42 |
| - handleConversationSubmit(query); |
43 |
| - } |
44 |
| - analyticsEvent(EVENT_NAMES['click:search'], { query, tabName }); |
45 |
| - } |
46 |
| - // eslint-disable-next-line react-hooks/exhaustive-deps |
47 |
| - }, [query, tabName]); |
48 |
| - |
49 |
| - const onTabSelect = (tabName: string): void => { |
50 |
| - setTabName(tabName); |
51 |
| - }; |
52 |
| - |
53 |
| - return ( |
54 |
| - <section> |
55 |
| - <SearchResults |
56 |
| - semanticResults={semanticResults} |
57 |
| - semanticIsLoading={isLoading} |
58 |
| - conversation={conversation} |
59 |
| - outputStream={outputStream} |
60 |
| - query={query} |
61 |
| - error={error || conversationError} |
62 |
| - isLoading={conversationIsLoading} |
63 |
| - hasScroll={hasScroll} |
64 |
| - onTabSelect={onTabSelect} |
65 |
| - limitResults={limitResults} |
66 |
| - /> |
67 |
| - </section> |
68 |
| - ); |
| 13 | +export const Search: FC<ISearchProps> = (props) => { |
| 14 | + return <SearchTab {...props} />; |
69 | 15 | };
|
0 commit comments