Created
July 19, 2020 23:47
-
-
Save gugazimmermann/632e0010ac0388d21b63a256648e7179 to your computer and use it in GitHub Desktop.
React Single-Player RPG - home
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import React, { useState, useContext } from 'react'; | |
| import Container from '@material-ui/core/Container'; | |
| import Paper from '@material-ui/core/Paper'; | |
| import AppBar from '@material-ui/core/AppBar'; | |
| import Toolbar from '@material-ui/core/Toolbar'; | |
| import IconButton from '@material-ui/core/IconButton'; | |
| import Typography from '@material-ui/core/Typography'; | |
| import MenuItem from '@material-ui/core/MenuItem'; | |
| import Menu from '@material-ui/core/Menu'; | |
| import Avatar from '@material-ui/core/Avatar'; | |
| import MenuIcon from '@material-ui/icons/Menu'; | |
| import { makeStyles, useTheme } from '@material-ui/core/styles'; | |
| import { Auth } from 'aws-amplify'; | |
| import { UserContext } from '../context/UserContext'; | |
| import styles from '../styles/home'; | |
| export default function Home() { | |
| const [{ user }] = useContext(UserContext); | |
| const theme = useTheme(); | |
| const useStyles = makeStyles(styles(theme)); | |
| const style = useStyles(); | |
| const [userMenuEl, setUserMenuEl] = useState(null); | |
| const open = Boolean(userMenuEl); | |
| const handleUserMenu = (event) => { | |
| setUserMenuEl(event.currentTarget); | |
| }; | |
| const handleUserMenuClose = () => { | |
| setUserMenuEl(null); | |
| }; | |
| return ( | |
| <Container component="main" maxWidth="sm" className={style.container}> | |
| <AppBar position="static"> | |
| <Toolbar> | |
| <IconButton | |
| edge="start" | |
| className={style.menuButton} | |
| color="inherit" | |
| aria-label="menu" | |
| > | |
| <MenuIcon /> | |
| </IconButton> | |
| <Typography variant="h6" className={style.menuTitle}> | |
| Home | |
| </Typography> | |
| {user && ( | |
| <> | |
| <IconButton | |
| aria-label="user account" | |
| aria-controls="menu-appbar" | |
| aria-haspopup="true" | |
| onClick={handleUserMenu} | |
| color="inherit" | |
| > | |
| <Avatar alt={user.name} src={`avatars/${user.avatar}`} /> | |
| </IconButton> | |
| <Menu | |
| id="menu-appbar" | |
| anchorEl={userMenuEl} | |
| anchorOrigin={{ | |
| vertical: 'top', | |
| horizontal: 'right', | |
| }} | |
| keepMounted | |
| transformOrigin={{ | |
| vertical: 'top', | |
| horizontal: 'right', | |
| }} | |
| open={open} | |
| onClose={handleUserMenuClose} | |
| > | |
| <MenuItem onClick={handleUserMenuClose}>Profile</MenuItem> | |
| <MenuItem | |
| onClick={() => Auth.signOut()} | |
| > | |
| Sign Out | |
| </MenuItem> | |
| </Menu> | |
| </> | |
| )} | |
| </Toolbar> | |
| </AppBar> | |
| <Paper className={style.paper}> | |
| <Typography variant="h6" className={style.menuTitle}> | |
| Welcome | |
| {' '} | |
| {user.name} | |
| </Typography> | |
| </Paper> | |
| </Container> | |
| ); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { grey } from '@material-ui/core/colors'; | |
| const styles = (theme) => ({ | |
| container: { | |
| height: '100%', | |
| backgroundColor: grey[50], | |
| }, | |
| paper: { | |
| flexGrow: 1, | |
| marginTop: theme.spacing(2), | |
| marginBottom: theme.spacing(2), | |
| padding: theme.spacing(1), | |
| }, | |
| menuButton: { | |
| marginRight: theme.spacing(1), | |
| }, | |
| menuTitle: { | |
| flexGrow: 1, | |
| }, | |
| }); | |
| export default styles; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment