diff options
author | eug-vs <eug-vs@keemail.me> | 2020-06-30 00:41:09 +0300 |
---|---|---|
committer | eug-vs <eug-vs@keemail.me> | 2020-06-30 00:41:09 +0300 |
commit | 1499c0126d1a7a2377b0267b761479100c636ee9 (patch) | |
tree | 5d48eea7b8dffcac324034703ebc4e30448d75c6 /src/components/Header | |
parent | aa63dea15c71ab014b4b57010574c7abf1f9628b (diff) | |
download | which-ui-1499c0126d1a7a2377b0267b761479100c636ee9.tar.gz |
feat!: create useNavigate hook
Diffstat (limited to 'src/components/Header')
-rw-r--r-- | src/components/Header/Header.tsx | 10 | ||||
-rw-r--r-- | src/components/Header/SearchBar.tsx | 9 |
2 files changed, 8 insertions, 11 deletions
diff --git a/src/components/Header/Header.tsx b/src/components/Header/Header.tsx index 49f427f..546ecc3 100644 --- a/src/components/Header/Header.tsx +++ b/src/components/Header/Header.tsx @@ -10,13 +10,10 @@ import AccountCircle from '@material-ui/icons/AccountCircle'; import NotificationsIcon from '@material-ui/icons/Notifications'; import HomeIcon from '@material-ui/icons/Home'; import { useAuth } from '../../hooks/useAuth'; +import { useNavigate } from '../../hooks/useNavigate'; import SearchBar from './SearchBar'; -interface PropTypes { - navigate: (prefix: string) => void; -} - const useStyles = makeStyles({ root: { display: 'flex', @@ -33,9 +30,10 @@ const useStyles = makeStyles({ } }); -const Header: React.FC<PropTypes> = ({ navigate }) => { +const Header: React.FC = () => { const classes = useStyles(); const { user } = useAuth(); + const { navigate } = useNavigate(); const handleHome = (): void => { navigate('feed'); @@ -53,7 +51,7 @@ const Header: React.FC<PropTypes> = ({ navigate }) => { <Typography variant="h5" className={classes.logo}> Which </Typography> - <SearchBar navigate={navigate} /> + <SearchBar /> <div> <IconButton onClick={handleHome}> <HomeIcon /> diff --git a/src/components/Header/SearchBar.tsx b/src/components/Header/SearchBar.tsx index bff16a0..253e77f 100644 --- a/src/components/Header/SearchBar.tsx +++ b/src/components/Header/SearchBar.tsx @@ -12,10 +12,8 @@ import { makeStyles } from '@material-ui/core/styles'; import { User } from 'which-types'; import { get } from '../../requests'; import UserStrip from '../UserStrip/UserStrip'; +import { useNavigate } from '../../hooks/useNavigate'; -interface PropTypes { - navigate: (prefix: string, id: string) => void; -} const INTERVAL = 300; const LIMIT = 7; @@ -36,10 +34,11 @@ const useStyles = makeStyles(theme => ({ } })); -const SearchBar: React.FC<PropTypes> = ({ navigate }) => { +const SearchBar: React.FC = () => { const [results, setResults] = useState<User[]>([]); const [query, setQuery] = useState<string>(''); const [debouncedQuery, setDebouncedQuery] = useState<string>(query); + const { navigate } = useNavigate(); const classes = useStyles(); useEffect(() => { @@ -79,7 +78,7 @@ const SearchBar: React.FC<PropTypes> = ({ navigate }) => { results.map((result, index) => ( <div key={result._id}> <ListItem button onClick={handleNavigate(index)}> - <UserStrip user={result} navigate={navigate} /> + <UserStrip user={result} /> </ListItem> {(index < results.length - 1) && <Divider />} </div> |