diff options
Diffstat (limited to 'src/components/Header/Header.tsx')
-rw-r--r-- | src/components/Header/Header.tsx | 88 |
1 files changed, 63 insertions, 25 deletions
diff --git a/src/components/Header/Header.tsx b/src/components/Header/Header.tsx index 294c250..41aeec7 100644 --- a/src/components/Header/Header.tsx +++ b/src/components/Header/Header.tsx @@ -3,9 +3,11 @@ import { AppBar, Toolbar, IconButton, - Typography, Avatar + Typography, + Avatar, + useMediaQuery } from '@material-ui/core'; -import { makeStyles } from '@material-ui/core/styles'; +import { makeStyles, useTheme } from '@material-ui/core/styles'; import AccountCircle from '@material-ui/icons/AccountCircle'; import NotificationsIcon from '@material-ui/icons/Notifications'; import HomeIcon from '@material-ui/icons/Home'; @@ -14,27 +16,36 @@ import { useNavigate } from '../../hooks/useNavigate'; import SearchBar from './SearchBar'; -const useStyles = makeStyles({ - root: { +const useStyles = makeStyles(theme => ({ + mobile: { + top: 'auto', + bottom: 0 + }, + toolbar: { display: 'flex', - justifyContent: 'space-around', + justifyContent: 'space-around' + }, + browserToolbar: { width: '60%', margin: 'auto' }, logo: { fontWeight: 'bold', - cursor: 'pointer' + cursor: 'pointer', + color: 'white' }, - avatar: { - width: 24, - height: 24 + round: { + width: theme.spacing(3), + height: theme.spacing(3) } -}); +})); const Header: React.FC = () => { const classes = useStyles(); const { user } = useAuth(); const { navigate } = useNavigate(); + const theme = useTheme(); + const isMobile = useMediaQuery(theme.breakpoints.down('sm')); const handleHome = (): void => { navigate('home'); @@ -53,31 +64,58 @@ const Header: React.FC = () => { navigate('notifications'); }; - return ( + const FeedButton = ( + <IconButton onClick={handleFeed}> + <HomeIcon /> + </IconButton> + ); + + const NotificationsButton = ( + <IconButton onClick={handleNotifications}> + <NotificationsIcon /> + </IconButton> + ); + + const ProfileButton = ( + <IconButton onClick={handleProfile}> + { + user?.avatarUrl + ? <Avatar className={classes.round} src={user?.avatarUrl} /> + : <AccountCircle /> + } + </IconButton> + ); + + const BrowserVersion = ( <AppBar position="fixed"> - <Toolbar className={classes.root}> + <Toolbar className={`${classes.toolbar} ${classes.browserToolbar}`}> <Typography variant="h5" className={classes.logo} onClick={handleHome}> Which </Typography> <SearchBar /> <div> - <IconButton onClick={handleFeed}> - <HomeIcon /> - </IconButton> - <IconButton onClick={handleNotifications}> - <NotificationsIcon /> - </IconButton> - <IconButton onClick={handleProfile}> - { - user?.avatarUrl - ? <Avatar className={classes.avatar} src={user?.avatarUrl} /> - : <AccountCircle /> - } - </IconButton> + {FeedButton} + {NotificationsButton} + {ProfileButton} </div> </Toolbar> </AppBar> ); + + const MobileVersion = ( + <AppBar position="fixed" className={classes.mobile}> + <Toolbar className={classes.toolbar}> + <IconButton onClick={handleHome}> + <Typography className={`${classes.logo} ${classes.round}`}>W</Typography> + </IconButton> + {FeedButton} + {NotificationsButton} + {ProfileButton} + </Toolbar> + </AppBar> + ); + + return isMobile ? MobileVersion : BrowserVersion; }; export default Header; |