diff options
Diffstat (limited to 'src/components/Header/Header.tsx')
| -rw-r--r-- | src/components/Header/Header.tsx | 99 | 
1 files changed, 72 insertions, 27 deletions
| diff --git a/src/components/Header/Header.tsx b/src/components/Header/Header.tsx index 72e40f8..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,28 +16,42 @@ 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' +    fontWeight: 'bold', +    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'); +  }; + +  const handleFeed = (): void => {      navigate('feed');    }; @@ -44,33 +60,62 @@ const Header: React.FC = () => {      else navigate('auth');    }; -  const handleNotifications = (): void => {}; +  const handleNotifications = (): void => { +    navigate('notifications'); +  }; + +  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> +  ); -  return ( +  const BrowserVersion = (      <AppBar position="fixed"> -      <Toolbar className={classes.root}> -        <Typography variant="h5" className={classes.logo}> +      <Toolbar className={`${classes.toolbar} ${classes.browserToolbar}`}> +        <Typography variant="h5" className={classes.logo} onClick={handleHome}>            Which          </Typography>          <SearchBar />          <div> -          <IconButton onClick={handleHome}> -            <HomeIcon /> -          </IconButton> -          <IconButton onClick={handleNotifications}> -            <NotificationsIcon /> -          </IconButton> -          <IconButton onClick={handleProfile}> -            { -              user?.avatarUrl?.match(/\.(jpeg|jpg|gif|png)$/) -                ? <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; | 
