diff options
author | Eugene Sokolov <eug-vs@keemail.me> | 2020-08-12 03:41:48 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-08-12 03:41:48 +0300 |
commit | 2dc5fc00347256982136deea98d483c444002595 (patch) | |
tree | bb3826d74842bc628d1c6aa9c43aae919faffcea /src/components/Header | |
parent | 94067ef2a0d9ac5c2aa5f45eca5366a2251ac04a (diff) | |
parent | 68c7660e13fc5613ef26de752bc360a792b3f935 (diff) | |
download | which-ui-2dc5fc00347256982136deea98d483c444002595.tar.gz |
Merge pull request #77 from which-ecosystem/redesign
Mobile search and basic drawer
Diffstat (limited to 'src/components/Header')
-rw-r--r-- | src/components/Header/Header.tsx | 22 | ||||
-rw-r--r-- | src/components/Header/MobileHeader.tsx | 20 | ||||
-rw-r--r-- | src/components/Header/SearchBar.tsx | 7 |
3 files changed, 32 insertions, 17 deletions
diff --git a/src/components/Header/Header.tsx b/src/components/Header/Header.tsx index 5621dbf..224f6b0 100644 --- a/src/components/Header/Header.tsx +++ b/src/components/Header/Header.tsx @@ -1,4 +1,4 @@ -import React from 'react'; +import React, { useState } from 'react'; import { useHistory } from 'react-router-dom'; import { IconButton, @@ -9,8 +9,7 @@ import { AccountCircle, Notifications, Home, - Menu, - Search + Menu } from '@material-ui/icons'; import { makeStyles, useTheme } from '@material-ui/core/styles'; @@ -19,6 +18,7 @@ import MobileHeader from './MobileHeader'; import BottomBar from './BottomBar'; import BrowserHeader from './BrowserHeader'; import Avatar from '../Avatar/Avatar'; +import Drawer from '../Drawer/Drawer'; const useStyles = makeStyles(theme => ({ @@ -39,6 +39,7 @@ const Header: React.FC = React.memo(() => { const theme = useTheme(); const history = useHistory(); const isMobile = useMediaQuery(theme.breakpoints.down('sm')); + const [isDrawerOpen, setIsDrawerOpen] = useState<boolean>(false); const handleHome = (): void => { history.push('/'); @@ -57,6 +58,10 @@ const Header: React.FC = React.memo(() => { history.push('/notifications'); }; + const handleMenu = (): void => { + setIsDrawerOpen(true); + }; + const feed = ( <IconButton onClick={handleFeed}> <Home /> @@ -70,17 +75,11 @@ const Header: React.FC = React.memo(() => { ); const menu = ( - <IconButton> + <IconButton onClick={handleMenu}> <Menu /> </IconButton> ); - const search = ( - <IconButton> - <Search /> - </IconButton> - ); - const logo = ( <Typography variant="h5" className={classes.logo} onClick={handleHome}> Which @@ -99,8 +98,9 @@ const Header: React.FC = React.memo(() => { return isMobile ? ( <> - <MobileHeader logo={logo} menu={menu} search={search} /> + <MobileHeader logo={logo} menu={menu} /> <BottomBar feed={feed} profile={profile} notifications={notifications} /> + <Drawer isOpen={isDrawerOpen} setIsOpen={setIsDrawerOpen} /> </> ) : ( <BrowserHeader logo={logo} profile={profile} notifications={notifications} feed={feed} /> diff --git a/src/components/Header/MobileHeader.tsx b/src/components/Header/MobileHeader.tsx index a20d54a..752e4bc 100644 --- a/src/components/Header/MobileHeader.tsx +++ b/src/components/Header/MobileHeader.tsx @@ -1,16 +1,18 @@ -import React from 'react'; +import React, { useState } from 'react'; import { AppBar, Toolbar, + IconButton, useScrollTrigger, Slide } from '@material-ui/core'; import { makeStyles } from '@material-ui/core/styles'; +import { Search, Clear } from '@material-ui/icons'; +import SearchBar from './SearchBar'; interface PropTypes { menu: JSX.Element; logo: JSX.Element; - search: JSX.Element; } const useStyles = makeStyles({ @@ -24,15 +26,23 @@ const useStyles = makeStyles({ const MobileHeader: React.FC<PropTypes> = React.memo(props => { const classes = useStyles(); const trigger = useScrollTrigger(); - const { menu, search, logo } = props; + const [isSearchOpen, setIsSearchOpen] = useState<boolean>(false); + + const { menu, logo } = props; + + const handleToggle = () => { + setIsSearchOpen(value => !value); + }; return ( <Slide appear={false} direction="down" in={!trigger}> <AppBar position="fixed"> <Toolbar className={classes.root}> {menu} - {logo} - {search} + {isSearchOpen ? <SearchBar callback={handleToggle} /> : logo} + <IconButton onClick={handleToggle}> + {isSearchOpen ? <Clear /> : <Search />} + </IconButton> </Toolbar> </AppBar> </Slide> diff --git a/src/components/Header/SearchBar.tsx b/src/components/Header/SearchBar.tsx index 8bfe0fb..ea6e6ac 100644 --- a/src/components/Header/SearchBar.tsx +++ b/src/components/Header/SearchBar.tsx @@ -15,6 +15,10 @@ import { User } from 'which-types'; import { get } from '../../requests'; import UserStrip from '../UserStrip/UserStrip'; +interface PropTypes { + callback?: () => void; +} + const INTERVAL = 300; const LIMIT = 7; @@ -37,7 +41,7 @@ const useStyles = makeStyles(theme => ({ } })); -const SearchBar: React.FC = React.memo(() => { +const SearchBar: React.FC<PropTypes> = React.memo(({ callback }) => { const [results, setResults] = useState<User[]>([]); const [query, setQuery] = useState<string>(''); const [debouncedQuery, setDebouncedQuery] = useState<string>(query); @@ -72,6 +76,7 @@ const SearchBar: React.FC = React.memo(() => { const { username } = results[index]; history.push(`/profile/${username}`); handleClose(); + if (callback) callback(); }; const SearchResults = ( |