Close the navbar after a search
This commit is contained in:
parent
e3ccabdcb9
commit
956856e0e7
@ -43,6 +43,7 @@ const AppNavBar = (props) => {
|
|||||||
placeholder="Search movies"
|
placeholder="Search movies"
|
||||||
path='/movies/search'
|
path='/movies/search'
|
||||||
history={props.history}
|
history={props.history}
|
||||||
|
setExpanded={setExpanded}
|
||||||
/>
|
/>
|
||||||
}/>
|
}/>
|
||||||
<Route path="/shows" render={(props) =>
|
<Route path="/shows" render={(props) =>
|
||||||
@ -50,6 +51,7 @@ const AppNavBar = (props) => {
|
|||||||
placeholder="Search shows"
|
placeholder="Search shows"
|
||||||
path='/shows/search'
|
path='/shows/search'
|
||||||
history={props.history}
|
history={props.history}
|
||||||
|
setExpanded={setExpanded}
|
||||||
/>
|
/>
|
||||||
}/>
|
}/>
|
||||||
<UserDropdown
|
<UserDropdown
|
||||||
@ -70,12 +72,13 @@ AppNavBar.propTypes = {
|
|||||||
|
|
||||||
export default connect(mapStateToProps)(AppNavBar);
|
export default connect(mapStateToProps)(AppNavBar);
|
||||||
|
|
||||||
const Search = (props) => {
|
const Search = ({ path, placeholder, setExpanded, history }) => {
|
||||||
const [search, setSearch] = useState("");
|
const [search, setSearch] = useState("");
|
||||||
|
|
||||||
const handleSearch = (ev) => {
|
const handleSearch = (ev) => {
|
||||||
ev.preventDefault();
|
ev.preventDefault();
|
||||||
props.history.push(`${props.path}/${encodeURI(search)}`);
|
history.push(`${path}/${encodeURI(search)}`);
|
||||||
|
setExpanded(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
return(
|
return(
|
||||||
@ -83,7 +86,7 @@ const Search = (props) => {
|
|||||||
<form className="input-group" onSubmit={(ev) => handleSearch(ev)}>
|
<form className="input-group" onSubmit={(ev) => handleSearch(ev)}>
|
||||||
<input
|
<input
|
||||||
className="form-control"
|
className="form-control"
|
||||||
placeholder={props.placeholder}
|
placeholder={placeholder}
|
||||||
value={search}
|
value={search}
|
||||||
onChange={(e) => setSearch(e.target.value)}
|
onChange={(e) => setSearch(e.target.value)}
|
||||||
/>
|
/>
|
||||||
@ -93,6 +96,7 @@ const Search = (props) => {
|
|||||||
}
|
}
|
||||||
Search.propTypes = {
|
Search.propTypes = {
|
||||||
placeholder: PropTypes.string.isRequired,
|
placeholder: PropTypes.string.isRequired,
|
||||||
|
setExpanded: PropTypes.func.isRequired,
|
||||||
path: PropTypes.string.isRequired,
|
path: PropTypes.string.isRequired,
|
||||||
history: PropTypes.object,
|
history: PropTypes.object,
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user