Skip to content

Commit

Permalink
Add missing files
Browse files Browse the repository at this point in the history
  • Loading branch information
taschetto committed Mar 31, 2021
1 parent b647c9c commit 31bd746
Show file tree
Hide file tree
Showing 4 changed files with 122 additions and 12 deletions.
1 change: 1 addition & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ module.exports = {
},
plugins: ['react', 'react-hooks'],
rules: {
'react/prop-types': ['off'],
'react-hooks/rules-of-hooks': 'error',
'react-hooks/exhaustive-deps': 'warn',
'react/default-props-match-prop-types': ['error'],
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"msw": "^0.28.0",
"npm-run-all": "^4.1.5",
"prettier": "^2.2.1",
"ramda": "^0.27.1",
"react": "^17.0.2",
"react-dom": "^17.0.2",
"react-hook-form": "^6.15.5",
Expand Down Expand Up @@ -60,4 +61,4 @@
"msw": {
"workerDirectory": "public"
}
}
}
126 changes: 115 additions & 11 deletions src/App.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,121 @@
import './App.css'

import { Redirect, Route, Router, Switch } from 'react-router-dom'
import { Button, AppBar, Toolbar, Typography } from '@material-ui/core'
import { makeStyles } from '@material-ui/core/styles'
import {
Redirect,
Route,
Router,
Switch,
useParams,
Link,
} from 'react-router-dom'
import { history } from 'utils/history'

import { Example01 } from './examples/01'
import { Example02 } from './examples/02'
import { Example03 } from './examples/03'
import { Example04 } from './examples/04'
import { Example05 } from './examples/05'
import { Example06 } from './examples/06'

export const App = () => (
<Router history={history}>
<Switch>
<Route exact path='/'>
<Redirect to='/example01' />
</Route>
<Route path='/example01' component={Example01} />
</Switch>
</Router>
)
const examples = [
{ key: 1, Component: Example01 },
{ key: 2, Component: Example02 },
{ key: 3, Component: Example03 },
{ key: 4, Component: Example04 },
{ key: 5, Component: Example05 },
{ key: 6, Component: Example06 },
]

const fallbackUi = () => <h1>Example not found</h1>

export const App = () => {
const classes = useStyles()
return (
<Router history={history}>
<div className={classes.container}>
<div className={classes.examples}>
<Switch>
<Route exact path='/'>
<Redirect to='/examples/01' />
</Route>
<Route
exact
path='/examples/:exampleId'
component={RenderExample}
/>
</Switch>
</div>
</div>
</Router>
)
}

const Menu = () => {
const classes = useStyles()
const { exampleId } = useParams()

const id = Number(exampleId)
const first = Number(id) === 1
const last = Number(id) >= examples.length

return (
<AppBar position='fixed' color='primary' className={classes.appBar}>
<Toolbar className={classes.toolbar}>
{!first && (
<Button
variant='outlined'
component={Link}
to={`/examples/${id - 1}`}>
Previous
</Button>
)}
<Typography variant='h4'>Example #{id}</Typography>
{!last && (
<Button
variant='outlined'
component={Link}
to={`/examples/${id + 1}`}>
Next
</Button>
)}
</Toolbar>
</AppBar>
)
}

const RenderExample = () => {
const { exampleId } = useParams()
const example = examples.find(({ key }) => Number(key) === Number(exampleId))
const Component = example?.Component ?? fallbackUi
return (
<>
<Menu />
<Component />
</>
)
}

const useStyles = makeStyles(() => ({
container: {
width: '100v',
height: '100vh',
display: 'flex',
},
examples: {
margin: 'auto',
maxWidth: '800px',
},
appBar: {
top: 'auto',
bottom: 0,
},
toolbar: {
justifyContent: 'center',
'& > *': {
marginLeft: 8,
marginRight: 8,
},
},
}))
4 changes: 4 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -8379,6 +8379,10 @@ raf@^3.4.1:
dependencies:
performance-now "^2.1.0"

ramda@^0.27.1:
version "0.27.1"
resolved "https://registry.yarnpkg.com/ramda/-/ramda-0.27.1.tgz#66fc2df3ef873874ffc2da6aa8984658abacf5c9"

randombytes@^2.0.0, randombytes@^2.0.1, randombytes@^2.0.5, randombytes@^2.1.0:
version "2.1.0"
resolved "https://registry.yarnpkg.com/randombytes/-/randombytes-2.1.0.tgz#df6f84372f0270dc65cdf6291349ab7a473d4f2a"
Expand Down

0 comments on commit 31bd746

Please sign in to comment.