diff options
author | Eugene Sokolov <eug-vs@keemail.me> | 2020-08-13 17:27:32 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-08-13 17:27:32 +0300 |
commit | d1e0dcd8538a61184eca50fbf7769c6d2943ff6b (patch) | |
tree | 9c2ba42d34e469d292fc1fe807e3f814a872a69e /src/components | |
parent | 2dc5fc00347256982136deea98d483c444002595 (diff) | |
parent | 52799ec4e4cd5801423ee0d2aa56039c061afdb4 (diff) | |
download | which-ui-d1e0dcd8538a61184eca50fbf7769c6d2943ff6b.tar.gz |
Merge pull request #78 from which-ecosystem/redesign
Move PollSubmission to separate page and add FAB
Diffstat (limited to 'src/components')
-rw-r--r-- | src/components/Avatar/Avatar.tsx | 16 | ||||
-rw-r--r-- | src/components/Fab/Fab.tsx | 50 | ||||
-rw-r--r-- | src/components/Header/BottomBar.tsx | 2 | ||||
-rw-r--r-- | src/components/Header/BrowserHeader.tsx | 24 | ||||
-rw-r--r-- | src/components/Header/Header.tsx | 7 |
5 files changed, 76 insertions, 23 deletions
diff --git a/src/components/Avatar/Avatar.tsx b/src/components/Avatar/Avatar.tsx index e445891..29754c9 100644 --- a/src/components/Avatar/Avatar.tsx +++ b/src/components/Avatar/Avatar.tsx @@ -1,35 +1,27 @@ import React from 'react'; import { useHistory } from 'react-router-dom'; import { Avatar as AvatarBase } from '@material-ui/core'; -import AccountCircle from '@material-ui/icons/AccountCircle'; import { User } from 'which-types'; interface PropTypes { - user: User; + user?: User; className?: string; } const Avatar: React.FC<PropTypes> = ({ user, className }) => { const history = useHistory(); - const { username, avatarUrl } = user; const handleClick = () => { - history.push(`/profile/${username}`); + if (user) history.push(`/profile/${user.username}`); }; - return avatarUrl ? ( + return ( <AvatarBase - src={avatarUrl} - alt={username[0].toUpperCase()} + src={user?.avatarUrl} onClick={handleClick} className={className} style={{ cursor: 'pointer' }} /> - ) : ( - <AccountCircle - className={className} - onClick={handleClick} - /> ); }; diff --git a/src/components/Fab/Fab.tsx b/src/components/Fab/Fab.tsx new file mode 100644 index 0000000..7ca2893 --- /dev/null +++ b/src/components/Fab/Fab.tsx @@ -0,0 +1,50 @@ +import React from 'react'; +import { useHistory } from 'react-router-dom'; +import { Fab as FabBase, Slide, useScrollTrigger } from '@material-ui/core/'; +import { makeStyles } from '@material-ui/core/styles'; +import PlusIcon from '@material-ui/icons/Add'; + +interface PropTypes { + hideOnScroll?: boolean; +} + +const useStyles = makeStyles(theme => ({ + root: { + zIndex: 1000, + position: 'fixed', + + [theme.breakpoints.down('sm')]: { + right: theme.spacing(2), + bottom: theme.spacing(8) + }, + [theme.breakpoints.up('md')]: { + right: theme.spacing(5), + bottom: theme.spacing(5) + } + } +})); + +const Fab: React.FC<PropTypes> = ({ hideOnScroll = false }) => { + const classes = useStyles(); + const history = useHistory(); + const trigger = useScrollTrigger(); + + const handleClick = () => { + history.push('/new'); + }; + + return ( + <Slide appear={false} direction="up" in={(!hideOnScroll) || !trigger}> + <FabBase + onClick={handleClick} + className={classes.root} + color="secondary" + > + <PlusIcon /> + </FabBase> + </Slide> + ); +}; + +export default Fab; + diff --git a/src/components/Header/BottomBar.tsx b/src/components/Header/BottomBar.tsx index 67fe219..6264929 100644 --- a/src/components/Header/BottomBar.tsx +++ b/src/components/Header/BottomBar.tsx @@ -26,7 +26,7 @@ const BottomBar: React.FC<PropTypes> = React.memo(props => { return ( <AppBar position="fixed" className={classes.root}> - <Toolbar className={classes.toolbar}> + <Toolbar variant="dense" className={classes.toolbar}> {notifications} {feed} {profile} diff --git a/src/components/Header/BrowserHeader.tsx b/src/components/Header/BrowserHeader.tsx index 2dda717..2acb69c 100644 --- a/src/components/Header/BrowserHeader.tsx +++ b/src/components/Header/BrowserHeader.tsx @@ -5,6 +5,7 @@ import SearchBar from './SearchBar'; interface PropTypes { logo: JSX.Element; + menu: JSX.Element; feed: JSX.Element; notifications: JSX.Element; profile: JSX.Element; @@ -18,7 +19,8 @@ const useStyles = makeStyles({ justifyContent: 'space-around' }, group: { - display: 'flex' + display: 'flex', + alignItems: 'center' } }); @@ -27,6 +29,7 @@ const BrowserHeader: React.FC<PropTypes> = React.memo(props => { const classes = useStyles(); const { logo, + menu, feed, notifications, profile @@ -34,13 +37,18 @@ const BrowserHeader: React.FC<PropTypes> = React.memo(props => { return ( <AppBar position="fixed"> - <Toolbar className={classes.root}> - {logo} - <SearchBar /> - <div className={classes.group}> - {feed} - {notifications} - {profile} + <Toolbar> + {menu} + <div className={classes.root}> + <div className={classes.group}> + {logo} + </div> + <SearchBar /> + <div className={classes.group}> + {feed} + {notifications} + {profile} + </div> </div> </Toolbar> </AppBar> diff --git a/src/components/Header/Header.tsx b/src/components/Header/Header.tsx index 224f6b0..93ba47d 100644 --- a/src/components/Header/Header.tsx +++ b/src/components/Header/Header.tsx @@ -89,7 +89,7 @@ const Header: React.FC = React.memo(() => { const profile = ( <IconButton onClick={handleProfile}> { - user + user?.avatarUrl ? <Avatar className={classes.avatar} user={user} /> : <AccountCircle className={classes.avatar} /> } @@ -103,7 +103,10 @@ const Header: React.FC = React.memo(() => { <Drawer isOpen={isDrawerOpen} setIsOpen={setIsDrawerOpen} /> </> ) : ( - <BrowserHeader logo={logo} profile={profile} notifications={notifications} feed={feed} /> + <> + <BrowserHeader menu={menu} logo={logo} profile={profile} notifications={notifications} feed={feed} /> + <Drawer isOpen={isDrawerOpen} setIsOpen={setIsDrawerOpen} /> + </> ); }); |