import React, { useMemo, useEffect, useCallback } 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 = React.memo(({ isOpen, setIsOpen }) => { const classes = useStyles(); const history = useHistory(); const { user, logout } = useAuth(); const handleOpen = useCallback(() => { setIsOpen(true); }, [setIsOpen]); const handleClose = useCallback(() => { setIsOpen(false); }, [setIsOpen]); useEffect(() => { // Close drawer on navigations return history.listen(() => handleClose()); }, [history, handleClose]); const handleLogout = useCallback(() => { logout(); history.push('/login'); }, [logout, history]); const handleAbout = useCallback(() => { history.push('/'); }, [history]); const iOS = useMemo(() => { return /iPad|iPhone|iPod/.test(navigator.userAgent); }, []); return ( {user && } {user && ( Logout )} About ); }); export default Drawer;