| 6694 |
stevensc |
1 |
import React, { useRef, useState } from 'react'
|
|
|
2 |
import { useForm } from 'react-hook-form'
|
|
|
3 |
import SearchIcon from '@mui/icons-material/Search'
|
|
|
4 |
|
|
|
5 |
import useWindowSize from '../../../../hooks/useWindowSize'
|
|
|
6 |
|
|
|
7 |
const NavSearch = () => {
|
|
|
8 |
const [showMobileSearch, setShowMobileSearch] = useState(false)
|
|
|
9 |
const searchInput = useRef(null)
|
|
|
10 |
|
|
|
11 |
const [innerWidth] = useWindowSize()
|
|
|
12 |
const { handleSubmit, register } = useForm()
|
|
|
13 |
|
|
|
14 |
const toggleSearch = () => {
|
|
|
15 |
setShowMobileSearch(!showMobileSearch)
|
|
|
16 |
}
|
|
|
17 |
|
|
|
18 |
const onSubmit = handleSubmit((data) => {
|
|
|
19 |
window.location.replace(`/search/entity/user?keyword=${data.keyword}`)
|
|
|
20 |
})
|
|
|
21 |
|
|
|
22 |
return (
|
|
|
23 |
<form
|
|
|
24 |
className="header__search show"
|
|
|
25 |
onClick={innerWidth < 992 && toggleSearch}
|
|
|
26 |
onSubmit={onSubmit}
|
|
|
27 |
ref={searchInput}
|
|
|
28 |
>
|
|
|
29 |
<SearchIcon />
|
|
|
30 |
<input type="text" placeholder="Search" name="keyword" ref={register} />
|
|
|
31 |
</form>
|
|
|
32 |
)
|
|
|
33 |
}
|
|
|
34 |
|
|
|
35 |
export default NavSearch
|