aboutsummaryrefslogtreecommitdiff
path: root/src/components
diff options
context:
space:
mode:
Diffstat (limited to 'src/components')
-rw-r--r--src/components/Drawer/Drawer.tsx86
-rw-r--r--src/components/Drawer/UserInfo.tsx38
-rw-r--r--src/components/Header/Header.tsx13
3 files changed, 134 insertions, 3 deletions
diff --git a/src/components/Drawer/Drawer.tsx b/src/components/Drawer/Drawer.tsx
new file mode 100644
index 0000000..eded40c
--- /dev/null
+++ b/src/components/Drawer/Drawer.tsx
@@ -0,0 +1,86 @@
+import React, { useMemo } from 'react';
+import { useHistory } from 'react-router-dom';
+import {
+ SwipeableDrawer,
+ List,
+ ListItem,
+ Typography,
+ Divider
+} from '@material-ui/core';
+import { ExitToApp as LogoutIcon, Info } from '@material-ui/icons';
+import { makeStyles } from '@material-ui/core/styles';
+
+import UserInfo from './UserInfo';
+import { useAuth } from '../../hooks/useAuth';
+
+interface PropTypes {
+ isOpen: boolean;
+ setIsOpen: (value: boolean) => void;
+}
+
+const useStyles = makeStyles(theme => ({
+ item: {
+ padding: theme.spacing(2, 14, 2, 2)
+ },
+ icon: {
+ marginRight: theme.spacing(1)
+ }
+}));
+
+
+const Drawer: React.FC<PropTypes> = React.memo(({ isOpen, setIsOpen }) => {
+ const classes = useStyles();
+ const history = useHistory();
+ const { user, logout } = useAuth();
+
+ const handleOpen = () => {
+ setIsOpen(true);
+ };
+
+ const handleClose = () => {
+ setIsOpen(false);
+ };
+
+ const handleLogout = () => {
+ logout();
+ handleClose();
+ };
+
+ const handleAbout = () => {
+ history.push('/');
+ handleClose();
+ };
+
+ const iOS = useMemo(() => {
+ return /iPad|iPhone|iPod/.test(navigator.userAgent);
+ }, []);
+
+ return (
+ <SwipeableDrawer
+ anchor="left"
+ open={isOpen}
+ onOpen={handleOpen}
+ onClose={handleClose}
+ disableBackdropTransition={!iOS}
+ disableDiscovery={iOS}
+ >
+ {user && <UserInfo user={user} />}
+ <Divider />
+ <List>
+ {user && (
+ <ListItem button className={classes.item} onClick={handleLogout}>
+ <LogoutIcon className={classes.icon} />
+ <Typography>Logout</Typography>
+ </ListItem>
+ )}
+ <ListItem button className={classes.item} onClick={handleAbout}>
+ <Info className={classes.icon} />
+ <Typography>About</Typography>
+ </ListItem>
+ </List>
+ </SwipeableDrawer>
+ );
+});
+
+export default Drawer;
+
diff --git a/src/components/Drawer/UserInfo.tsx b/src/components/Drawer/UserInfo.tsx
new file mode 100644
index 0000000..027f076
--- /dev/null
+++ b/src/components/Drawer/UserInfo.tsx
@@ -0,0 +1,38 @@
+import React from 'react';
+import { Typography } from '@material-ui/core';
+import { makeStyles } from '@material-ui/core/styles';
+import { User } from 'which-types';
+
+import Avatar from '../Avatar/Avatar';
+
+interface PropTypes {
+ user: User;
+}
+
+const useStyles = makeStyles(theme => ({
+ root: {
+ padding: theme.spacing(4, 10),
+ textAlign: 'center'
+ },
+ avatar: {
+ width: theme.spacing(14),
+ height: theme.spacing(14)
+ }
+}));
+
+
+const UserInfo: React.FC<PropTypes> = React.memo(({ user }) => {
+ const classes = useStyles();
+
+ return (
+ <div className={classes.root}>
+ <Avatar user={user} className={classes.avatar} />
+ <Typography variant="h5">
+ {user.username}
+ </Typography>
+ </div>
+ );
+});
+
+export default UserInfo;
+
diff --git a/src/components/Header/Header.tsx b/src/components/Header/Header.tsx
index 461a1f2..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,7 +9,7 @@ import {
AccountCircle,
Notifications,
Home,
- Menu,
+ Menu
} from '@material-ui/icons';
import { makeStyles, useTheme } from '@material-ui/core/styles';
@@ -18,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 => ({
@@ -38,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('/');
@@ -56,6 +58,10 @@ const Header: React.FC = React.memo(() => {
history.push('/notifications');
};
+ const handleMenu = (): void => {
+ setIsDrawerOpen(true);
+ };
+
const feed = (
<IconButton onClick={handleFeed}>
<Home />
@@ -69,7 +75,7 @@ const Header: React.FC = React.memo(() => {
);
const menu = (
- <IconButton>
+ <IconButton onClick={handleMenu}>
<Menu />
</IconButton>
);
@@ -94,6 +100,7 @@ const Header: React.FC = React.memo(() => {
<>
<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} />