( props: Omit<PostsSearchProps, 'onSubmitQuery'>, )
| 18 | import { feature } from '@dailydotdev/shared/src/lib/featureManagement'; |
| 19 | |
| 20 | export default function RouterPostsSearch( |
| 21 | props: Omit<PostsSearchProps, 'onSubmitQuery'>, |
| 22 | ): ReactElement { |
| 23 | const router = useRouter(); |
| 24 | const isPhone = useIsPhone(); |
| 25 | const routeQuery = router.query.q?.toString() ?? ''; |
| 26 | const [draft, setDraft] = useState(routeQuery); |
| 27 | |
| 28 | useEffect(() => { |
| 29 | setDraft(routeQuery); |
| 30 | }, [routeQuery]); |
| 31 | const { time, contentCurationFilter, postTypesFilter } = |
| 32 | useSearchContextProvider(); |
| 33 | const { logEvent } = useLogContext(); |
| 34 | const { getFeatureValue } = useFeaturesReadyContext(); |
| 35 | |
| 36 | const onSubmitQuery = (query: string): Promise<boolean> => { |
| 37 | logEvent({ |
| 38 | event_name: LogEvent.SubmitSearch, |
| 39 | extra: JSON.stringify({ |
| 40 | query, |
| 41 | provider: SearchProviderEnum.Posts, |
| 42 | search_version: getFeatureValue(feature.searchVersion), |
| 43 | filters: { |
| 44 | time, |
| 45 | contentCuration: contentCurationFilter, |
| 46 | postTypes: postTypesFilter, |
| 47 | }, |
| 48 | }), |
| 49 | }); |
| 50 | |
| 51 | return router.replace({ |
| 52 | pathname: router?.pathname ? router?.pathname : '/search', |
| 53 | query: { |
| 54 | q: query, |
| 55 | ...getSearchTimeQueryParam(time), |
| 56 | ...getSearchContentCurationQueryParam(contentCurationFilter), |
| 57 | ...getSearchPostTypesQueryParam(postTypesFilter), |
| 58 | }, |
| 59 | }); |
| 60 | }; |
| 61 | |
| 62 | const onClearQuery = () => { |
| 63 | return router.replace({ |
| 64 | pathname: router?.pathname ? router?.pathname : '/search', |
| 65 | }); |
| 66 | }; |
| 67 | |
| 68 | if (isPhone) { |
| 69 | const { placeholder } = props; |
| 70 | |
| 71 | return ( |
| 72 | <ShellField |
| 73 | placeholder={placeholder ?? 'Search'} |
| 74 | value={draft} |
| 75 | onChange={(value) => { |
| 76 | setDraft(value); |
| 77 | if (!value && router.query.q) { |
nothing calls this directly
no test coverage detected