aboutsummaryrefslogtreecommitdiff
path: root/src/components/Header
diff options
context:
space:
mode:
Diffstat (limited to 'src/components/Header')
-rw-r--r--src/components/Header/BottomBar.tsx39
-rw-r--r--src/components/Header/BrowserHeader.tsx51
-rw-r--r--src/components/Header/Header.tsx103
-rw-r--r--src/components/Header/MobileHeader.tsx43
4 files changed, 178 insertions, 58 deletions
diff --git a/src/components/Header/BottomBar.tsx b/src/components/Header/BottomBar.tsx
new file mode 100644
index 0000000..67fe219
--- /dev/null
+++ b/src/components/Header/BottomBar.tsx
@@ -0,0 +1,39 @@
+import React from 'react';
+import { AppBar, Toolbar } from '@material-ui/core';
+import { makeStyles } from '@material-ui/core/styles';
+
+interface PropTypes {
+ profile: JSX.Element;
+ feed: JSX.Element;
+ notifications: JSX.Element;
+}
+
+const useStyles = makeStyles({
+ root: {
+ top: 'auto',
+ bottom: 0
+ },
+ toolbar: {
+ display: 'flex',
+ justifyContent: 'space-around'
+ }
+});
+
+
+const BottomBar: React.FC<PropTypes> = React.memo(props => {
+ const classes = useStyles();
+ const { profile, feed, notifications } = props;
+
+ return (
+ <AppBar position="fixed" className={classes.root}>
+ <Toolbar className={classes.toolbar}>
+ {notifications}
+ {feed}
+ {profile}
+ </Toolbar>
+ </AppBar>
+ );
+});
+
+export default BottomBar;
+
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 c3a678c..5621dbf 100644
--- a/src/components/Header/Header.tsx
+++ b/src/components/Header/Header.tsx
@@ -1,47 +1,38 @@
import React from 'react';
import { useHistory } from 'react-router-dom';
import {
- AppBar,
- Toolbar,
IconButton,
Typography,
- Avatar,
useMediaQuery
} from '@material-ui/core';
+import {
+ AccountCircle,
+ Notifications,
+ Home,
+ Menu,
+ Search
+} from '@material-ui/icons';
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';
import { useAuth } from '../../hooks/useAuth';
-import SearchBar from './SearchBar';
+import MobileHeader from './MobileHeader';
+import BottomBar from './BottomBar';
+import BrowserHeader from './BrowserHeader';
+import Avatar from '../Avatar/Avatar';
const useStyles = makeStyles(theme => ({
- mobile: {
- top: 'auto',
- bottom: 0
- },
- 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)
}
}));
-
const Header: React.FC = React.memo(() => {
const classes = useStyles();
const { user } = useAuth();
@@ -66,58 +57,54 @@ const Header: React.FC = React.memo(() => {
history.push('/notifications');
};
- const FeedButton = (
+ const feed = (
<IconButton onClick={handleFeed}>
- <HomeIcon />
+ <Home />
</IconButton>
);
- const NotificationsButton = (
+ const notifications = (
<IconButton onClick={handleNotifications}>
- <NotificationsIcon />
+ <Notifications />
</IconButton>
);
- const ProfileButton = (
- <IconButton onClick={handleProfile}>
- {
- user?.avatarUrl
- ? <Avatar className={classes.round} src={user?.avatarUrl} />
- : <AccountCircle />
- }
+ const menu = (
+ <IconButton>
+ <Menu />
</IconButton>
);
- const BrowserVersion = (
- <AppBar position="fixed">
- <Toolbar className={`${classes.toolbar} ${classes.browserToolbar}`}>
- <Typography variant="h5" className={classes.logo} onClick={handleHome}>
- Which
- </Typography>
- <SearchBar />
- <div>
- {FeedButton}
- {NotificationsButton}
- {ProfileButton}
- </div>
- </Toolbar>
- </AppBar>
+ const search = (
+ <IconButton>
+ <Search />
+ </IconButton>
+ );
+
+ const logo = (
+ <Typography variant="h5" className={classes.logo} onClick={handleHome}>
+ Which
+ </Typography>
);
- 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>
+ const profile = (
+ <IconButton onClick={handleProfile}>
+ {
+ user
+ ? <Avatar className={classes.avatar} user={user} />
+ : <AccountCircle className={classes.avatar} />
+ }
+ </IconButton>
);
- return isMobile ? MobileVersion : BrowserVersion;
+ return isMobile ? (
+ <>
+ <MobileHeader logo={logo} menu={menu} search={search} />
+ <BottomBar feed={feed} profile={profile} notifications={notifications} />
+ </>
+ ) : (
+ <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
new file mode 100644
index 0000000..a20d54a
--- /dev/null
+++ b/src/components/Header/MobileHeader.tsx
@@ -0,0 +1,43 @@
+import React from 'react';
+import {
+ AppBar,
+ Toolbar,
+ useScrollTrigger,
+ Slide
+} from '@material-ui/core';
+import { makeStyles } from '@material-ui/core/styles';
+
+interface PropTypes {
+ menu: JSX.Element;
+ logo: JSX.Element;
+ search: JSX.Element;
+}
+
+const useStyles = makeStyles({
+ root: {
+ display: 'flex',
+ justifyContent: 'space-between'
+ }
+});
+
+
+const MobileHeader: React.FC<PropTypes> = React.memo(props => {
+ const classes = useStyles();
+ const trigger = useScrollTrigger();
+ const { menu, search, logo } = props;
+
+ return (
+ <Slide appear={false} direction="down" in={!trigger}>
+ <AppBar position="fixed">
+ <Toolbar className={classes.root}>
+ {menu}
+ {logo}
+ {search}
+ </Toolbar>
+ </AppBar>
+ </Slide>
+ );
+});
+
+export default MobileHeader;
+