diff options
author | eug-vs <eug-vs@keemail.me> | 2020-08-11 22:00:10 +0300 |
---|---|---|
committer | eug-vs <eug-vs@keemail.me> | 2020-08-11 22:00:10 +0300 |
commit | a9d713a73b65847af419016d2d97c4e8dab950f9 (patch) | |
tree | 653bcd474bc0aff2c4bd4c7dfba19acf89c81c81 /src/components/Header | |
parent | 4bcabf751b8292fee696db5e027f38b1838b0be6 (diff) | |
download | which-ui-a9d713a73b65847af419016d2d97c4e8dab950f9.tar.gz |
refactor: cleanup header components
Diffstat (limited to 'src/components/Header')
-rw-r--r-- | src/components/Header/BottomBar.tsx | 4 | ||||
-rw-r--r-- | src/components/Header/BrowserHeader.tsx | 51 | ||||
-rw-r--r-- | src/components/Header/Header.tsx | 40 | ||||
-rw-r--r-- | src/components/Header/MobileHeader.tsx | 15 |
4 files changed, 72 insertions, 38 deletions
diff --git a/src/components/Header/BottomBar.tsx b/src/components/Header/BottomBar.tsx index 57efb3e..67fe219 100644 --- a/src/components/Header/BottomBar.tsx +++ b/src/components/Header/BottomBar.tsx @@ -8,7 +8,7 @@ interface PropTypes { notifications: JSX.Element; } -const useStyles = makeStyles(theme => ({ +const useStyles = makeStyles({ root: { top: 'auto', bottom: 0 @@ -17,7 +17,7 @@ const useStyles = makeStyles(theme => ({ display: 'flex', justifyContent: 'space-around' } -})); +}); const BottomBar: React.FC<PropTypes> = React.memo(props => { diff --git a/src/components/Header/BrowserHeader.tsx b/src/components/Header/BrowserHeader.tsx new file mode 100644 index 0000000..2dda717 --- /dev/null +++ b/src/components/Header/BrowserHeader.tsx @@ -0,0 +1,51 @@ +import React from 'react'; +import { AppBar, Toolbar } from '@material-ui/core'; +import { makeStyles } from '@material-ui/core/styles'; +import SearchBar from './SearchBar'; + +interface PropTypes { + logo: JSX.Element; + feed: JSX.Element; + notifications: JSX.Element; + profile: JSX.Element; +} + +const useStyles = makeStyles({ + root: { + width: '60%', + margin: 'auto', + display: 'flex', + justifyContent: 'space-around' + }, + group: { + display: 'flex' + } +}); + + +const BrowserHeader: React.FC<PropTypes> = React.memo(props => { + const classes = useStyles(); + const { + logo, + feed, + notifications, + profile + } = props; + + return ( + <AppBar position="fixed"> + <Toolbar className={classes.root}> + {logo} + <SearchBar /> + <div className={classes.group}> + {feed} + {notifications} + {profile} + </div> + </Toolbar> + </AppBar> + ); +}); + +export default BrowserHeader; + diff --git a/src/components/Header/Header.tsx b/src/components/Header/Header.tsx index b314d79..344b839 100644 --- a/src/components/Header/Header.tsx +++ b/src/components/Header/Header.tsx @@ -1,8 +1,6 @@ import React from 'react'; import { useHistory } from 'react-router-dom'; import { - AppBar, - Toolbar, IconButton, Typography, Avatar, @@ -13,31 +11,23 @@ import { Notifications, Home, Menu, - Search, + Search } from '@material-ui/icons'; import { makeStyles, useTheme } from '@material-ui/core/styles'; import { useAuth } from '../../hooks/useAuth'; -import SearchBar from './SearchBar'; import MobileHeader from './MobileHeader'; import BottomBar from './BottomBar'; +import BrowserHeader from './BrowserHeader'; const useStyles = makeStyles(theme => ({ - toolbar: { - display: 'flex', - justifyContent: 'space-around' - }, - browserToolbar: { - width: '60%', - margin: 'auto' - }, logo: { fontWeight: 'bold', cursor: 'pointer', color: 'white' }, - round: { + avatar: { width: theme.spacing(3), height: theme.spacing(3) } @@ -86,7 +76,7 @@ const Header: React.FC = React.memo(() => { ); const search = ( - <IconButton onClick={handleNotifications}> + <IconButton> <Search /> </IconButton> ); @@ -97,36 +87,24 @@ const Header: React.FC = React.memo(() => { </Typography> ); - const profile= ( + const profile = ( <IconButton onClick={handleProfile}> { user?.avatarUrl - ? <Avatar className={classes.round} src={user?.avatarUrl} /> + ? <Avatar className={classes.avatar} src={user?.avatarUrl} /> : <AccountCircle /> } </IconButton> ); - const BrowserVersion = ( - <AppBar position="fixed"> - <Toolbar className={`${classes.toolbar} ${classes.browserToolbar}`}> - {logo} - <SearchBar /> - <div> - {feed} - {notifications} - {profile} - </div> - </Toolbar> - </AppBar> - ); - return isMobile ? ( <> <MobileHeader logo={logo} menu={menu} search={search} /> <BottomBar feed={feed} profile={profile} notifications={notifications} /> </> - ) : BrowserVersion; + ) : ( + <BrowserHeader logo={logo} profile={profile} notifications={notifications} feed={feed} /> + ); }); export default Header; diff --git a/src/components/Header/MobileHeader.tsx b/src/components/Header/MobileHeader.tsx index fbbd37a..a20d54a 100644 --- a/src/components/Header/MobileHeader.tsx +++ b/src/components/Header/MobileHeader.tsx @@ -1,5 +1,10 @@ import React from 'react'; -import { AppBar, Toolbar, useScrollTrigger, Slide } from '@material-ui/core'; +import { + AppBar, + Toolbar, + useScrollTrigger, + Slide +} from '@material-ui/core'; import { makeStyles } from '@material-ui/core/styles'; interface PropTypes { @@ -8,12 +13,12 @@ interface PropTypes { search: JSX.Element; } -const useStyles = makeStyles(theme => ({ +const useStyles = makeStyles({ root: { display: 'flex', - justifyContent: 'space-between', - }, -})); + justifyContent: 'space-between' + } +}); const MobileHeader: React.FC<PropTypes> = React.memo(props => { |