Skip to content

Commit

Permalink
#803 React and Material UI dependency updated. Layout improvements in…
Browse files Browse the repository at this point in the history
… progress
  • Loading branch information
mateusmarquezini committed Aug 18, 2019
1 parent efcce58 commit dd6c519
Show file tree
Hide file tree
Showing 8 changed files with 356 additions and 229 deletions.
185 changes: 83 additions & 102 deletions package-lock.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"@material-ui/core": "^4.3.2",
"@material-ui/icons": "^4.2.1",
"autoprefixer": "9.6.1",
"clsx": "^1.0.4",
"fs-extra": "8.1.0",
"html-webpack-plugin": "3.2.0",
"lodash": "4.17.15",
Expand Down
17 changes: 9 additions & 8 deletions src/app.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,15 @@ const Scoreboard = require('./learn/math/drill/scoreboard');
function app() {
return (
<div>
<Route path="/" component={Menu} />
<Switch>
<Route path="/" exact component={Home} />
<Route path="/math/drill" exact component={Drill} />
<Route path="/math/score" exact component={Scoreboard} />
<Route path="/help" exact component={Help} />
<Redirect to="/" />
</Switch>
<Menu>
<Switch>
<Route path="/" exact component={Home} />
<Route path="/math/drill" exact component={Drill} />
<Route path="/math/score" exact component={Scoreboard} />
<Route path="/help" exact component={Help} />
<Redirect to="/" />
</Switch>
</Menu>
</div>
);
}
Expand Down
6 changes: 6 additions & 0 deletions src/assets/github-logo.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
27 changes: 25 additions & 2 deletions src/index.jsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,35 @@
const { MuiThemeProvider, createMuiTheme } = require('@material-ui/core/styles');
const React = require('react');
const ReactDOM = require('react-dom');
const lightBaseTheme = require('material-ui/styles/baseThemes/lightBaseTheme').default;
const { BrowserRouter } = require('react-router-dom');
const deepOrange = require('@material-ui/core/colors/deepOrange').default;
const amber = require('@material-ui/core/colors/amber').default;
const poly = require('./poly');
const App = require('./app.jsx');

const theme = createMuiTheme(lightBaseTheme);
const theme = createMuiTheme(
{
palette: {
type: 'light',
primary: deepOrange,
secondary: amber,
},
typography: {
fontFamily: [
'-apple-system',
'BlinkMacSystemFont',
'"Segoe UI"',
'Roboto',
'"Helvetica Neue"',
'Arial',
'sans-serif',
'"Apple Color Emoji"',
'"Segoe UI Emoji"',
'"Segoe UI Symbol"',
].join(','),
},
},
);

poly(undefined, (err) => {
if (err) {
Expand Down
82 changes: 4 additions & 78 deletions src/learn/home.jsx
Original file line number Diff line number Diff line change
@@ -1,88 +1,14 @@
const Fab = require('@material-ui/core/Fab').default;
const { Link } = require('react-router-dom');
const Button = require('@material-ui/core/Button').default;
const React = require('react');
const { Share, BugReport } = require('@material-ui/icons');
const Tooltip = require('@material-ui/core/Tooltip').default;
const Typography = require('@material-ui/core/Typography').default;

const style = {
marginTop: '20px',
};

const githubIconStyle = {
textAlign: 'right',
marginTop: '20px',
};

function share() {
navigator.share({
title: 'Math Drill',
text: 'Math Exercises for Kids',
url: 'https://learn.guyellisrocks.com',
})
// eslint-disable-next-line no-console
.then(() => console.log('Successful share'))
// eslint-disable-next-line no-console
.catch(error => console.log('Error sharing', error));
}

function shareComponent() {
if (!navigator.share) {
return null;
}
const shareStyle = {
paddingLeft: '20px',
};
return (
<span style={shareStyle}>
<Tooltip title="Share">
<Fab
color="primary"
aria-label="add"
onClick={share}
>
<Share />
</Fab>
</Tooltip>
</span>
);
}

function home() {
return (
<div>
<div style={githubIconStyle}>
<a
aria-label="Issue guyellis/learn on GitHub"
href="https://github.com/guyellis/learn/issues"
rel="noopener noreferrer"
target="_blank"
>
<Tooltip title="Bugs and Issues">
<Fab
color="primary"
aria-label="add"
>
<BugReport />
</Fab>
</Tooltip>
</a>
{shareComponent()}
</div>
<div>
<Link to="/math/drill">
<Button variant="contained" color="primary">Math Drill</Button>
</Link>
</div>
<div style={style}>
<Link to="/math/score">
<Button variant="contained" color="primary">Scoreboard</Button>
</Link>
</div>
<div style={style}>
<Link to="/help">
<Button variant="contained" color="primary">Help</Button>
</Link>
<Typography variant="h2" gutterBottom>
Home
</Typography>
</div>
</div>
);
Expand Down
200 changes: 161 additions & 39 deletions src/learn/menu.jsx
Original file line number Diff line number Diff line change
@@ -1,50 +1,172 @@
const { Link } = require('react-router-dom');
const Toolbar = require('@material-ui/core/Toolbar').default;
// const PropTypes = require('prop-types');
const Button = require('@material-ui/core/Button').default;
const clsx = require('clsx').default;
const CssBaseline = require('@material-ui/core/CssBaseline').default;
const Tooltip = require('@material-ui/core/Tooltip').default;
const AppBar = require('@material-ui/core/AppBar').default;
const Typography = require('@material-ui/core/Typography').default;
const IconButton = require('@material-ui/core/IconButton').default;
const Drawer = require('@material-ui/core/Drawer').default;
const MenuIcon = require('@material-ui/icons/Menu').default;
const ChevronLeftIcon = require('@material-ui/icons/ChevronLeft').default;
const ChevronRightIcon = require('@material-ui/icons/ChevronRight').default;
const Home = require('@material-ui/icons/Home').default;
const Share = require('@material-ui/icons/Share').default;
const VideoGameAsset = require('@material-ui/icons/VideoGameAsset').default;
const Help = require('@material-ui/icons/Help').default;
const Score = require('@material-ui/icons/Score').default;
const Divider = require('@material-ui/core/Divider').default;
const List = require('@material-ui/core/List').default;
const ListItem = require('@material-ui/core/ListItem').default;
const ListItemIcon = require('@material-ui/core/ListItemIcon').default;
const ListItemText = require('@material-ui/core/ListItemText').default;
const React = require('react');
const { useState } = require('react');
const { useTheme } = require('@material-ui/core/styles');
const Grid = require('@material-ui/core/Grid').default;
const useStyles = require('./menuStyles');
const github = require('../assets/github-logo.svg');

class ToolbarMenu extends React.Component {
constructor(props) {
super(props);
// TODO: Fix and remove this ESLint disable
// eslint-disable-next-line react/state-in-constructor
this.state = {
value: 3,
};
this.handleChange = (event, index, value) => this.setState({ value });
}
const ToolbarMenu = ({ children }) => {
const classes = useStyles();
const theme = useTheme();
const [open, setOpen] = useState(false);

render() {
const handleDrawerOpen = () => {
setOpen(true);
};

const handleDrawerClose = () => {
setOpen(false);
};

const share = () => {
navigator.share({
title: 'Math Drill',
text: 'Math Exercises for Kids',
url: 'https://learn.guyellisrocks.com',
})
// eslint-disable-next-line no-console
.then(() => console.log('Successful share'))
// eslint-disable-next-line no-console
.catch(error => console.log('Error sharing', error));
};

const shareComponent = () => {
if (navigator.share) {
return null;
}
return (
<Toolbar>
<Link to="/">
<Button variant="contained" color="primary">Home</Button>
</Link>
<Link to="/math/drill">
<Button variant="contained" color="primary">Drill</Button>
</Link>
<Link to="/math/score">
<Button variant="contained" color="primary">Score</Button>
</Link>
<Link to="/help">
<Button variant="contained" color="primary">Help</Button>
</Link>
</Toolbar>
<Tooltip title="Share">
<ListItem onClick={share} button>
<ListItemIcon><Share /></ListItemIcon>
<ListItemText primary="Share" />
</ListItem>
</Tooltip>
);
}
}
};

// ToolbarMenu.propTypes = {
// match: PropTypes.shape({
// params: PropTypes.shape({
// id: PropTypes.string.isRequired,
// slug: PropTypes.string.isRequired,
// }).isRequired,
// }).isRequired,
// history: React.PropTypes.shape({
// push: React.PropTypes.func.isRequired,
// }).isRequired,
// };
return (
<div className={classes.root}>
<CssBaseline />
<AppBar
position="fixed"
className={clsx(classes.appBar, { [classes.appBarShift]: open })}
>
<Toolbar>
<IconButton
color="inherit"
aria-label="open drawer"
onClick={handleDrawerOpen}
edge="start"
className={clsx(classes.menuButton, { [classes.hide]: open })}
>
<MenuIcon />
</IconButton>
<div className={classes.appLabel}>
<Typography variant="h6" noWrap>
LEARN
</Typography>
</div>
<Grid
container
direction="row"
justify="flex-end"
alignItems="center"
>
<Tooltip title="Fork me!">
<a
aria-label="Fork guyellis/learn on GitHub"
href="https://github.com/guyellis/learn"
rel="noopener noreferrer"
target="_blank"
>
<img src={github} alt="github" height={30} width={30} />
</a>
</Tooltip>
</Grid>
</Toolbar>
</AppBar>
<Drawer
variant="permanent"
className={clsx(classes.drawer, {
[classes.drawerOpen]: open, [classes.drawerClose]: !open,
})}
classes={{
paper: clsx({ [classes.drawerOpen]: open, [classes.drawerClose]: !open }),
}}
open={open}
>
<div className={classes.toolbar}>
<IconButton onClick={handleDrawerClose}>
{theme.direction === 'rtl' ? <ChevronRightIcon /> : <ChevronLeftIcon />}
</IconButton>
</div>
<Divider />
<List>
<Link className={classes.link} to="/">
<Tooltip title="Home">
<ListItem button>
<ListItemIcon><Home /></ListItemIcon>
<ListItemText primary="Home" />
</ListItem>
</Tooltip>
</Link>
<Link className={classes.link} to="/math/drill">
<Tooltip title="Drill">
<ListItem button>
<ListItemIcon><VideoGameAsset /></ListItemIcon>
<ListItemText primary="Drill" />
</ListItem>
</Tooltip>
</Link>
<Link className={classes.link} to="/math/score">
<Tooltip title="Score">
<ListItem button>
<ListItemIcon><Score /></ListItemIcon>
<ListItemText primary="Score" />
</ListItem>
</Tooltip>
</Link>
<Link className={classes.link} to="/help">
<Tooltip title="Help">
<ListItem button>
<ListItemIcon><Help /></ListItemIcon>
<ListItemText primary="Help" />
</ListItem>
</Tooltip>
</Link>
</List>
<Divider />
{shareComponent()}
</Drawer>
<main className={classes.content}>
<div className={classes.toolbar} />
{children}
</main>
</div>
);
};

module.exports = ToolbarMenu;
Loading

0 comments on commit dd6c519

Please sign in to comment.