({ router, className, showButton, location, ...rest }: Props)
| 58 | } |
| 59 | |
| 60 | export default function SearchBox({ router, className, showButton, location, ...rest }: Props) { |
| 61 | const view = useFragment( |
| 62 | graphql` |
| 63 | fragment SearchBox_view on View { |
| 64 | queryInfo { |
| 65 | phrases |
| 66 | |
| 67 | topics { |
| 68 | displayName |
| 69 | id |
| 70 | } |
| 71 | } |
| 72 | } |
| 73 | `, |
| 74 | rest.view, |
| 75 | ) |
| 76 | |
| 77 | const pathname = location.pathname |
| 78 | const [selectedScope, setSelectedScope] = useState('Everything') |
| 79 | |
| 80 | const handleReturn = useCallback( |
| 81 | (event: KeyboardEvent<Element>, editorState: EditorState): DraftHandleValue => { |
| 82 | const query = queryFromState(editorState).toString() |
| 83 | const searchPathname = pathnameFor(pathname, selectedScope) |
| 84 | |
| 85 | if (query === '') { |
| 86 | router.push({ pathname: searchPathname }) |
| 87 | return 'handled' |
| 88 | } |
| 89 | |
| 90 | router.push({ pathname: searchPathname, query: { q: query } }) |
| 91 | return 'handled' |
| 92 | }, [router, pathname, selectedScope], |
| 93 | ) |
| 94 | |
| 95 | const onSelectChange = useCallback((event: FormEvent<HTMLSelectElement>) => { |
| 96 | const { value } = event.currentTarget |
| 97 | setSelectedScope(value) |
| 98 | }, [setSelectedScope]) |
| 99 | |
| 100 | const actualClassName = classNames('searchBoxInnerSearchBox input-group px-3', className) |
| 101 | |
| 102 | return ( |
| 103 | <form className={actualClassName} onSubmit={onFormSubmit}> |
| 104 | <TextInput |
| 105 | handleReturn={handleReturn} |
| 106 | queryInfo={view?.queryInfo} |
| 107 | /> |
| 108 | <div className="input-group-button searchBoxInnerButtonContainer"> |
| 109 | <SelectScope |
| 110 | pathname={pathname} |
| 111 | selectedScope={selectedScope} |
| 112 | onChange={onSelectChange} |
| 113 | /> |
| 114 | </div> |
| 115 | </form> |
| 116 | ) |
| 117 | } |
nothing calls this directly
no test coverage detected