diff options
author | Anton Dubik <anton.dubik33@gmail.com> | 2020-01-07 00:52:52 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-01-07 00:52:52 +0300 |
commit | 4931f205e1250c649b3a48b96a7823a9d52615ff (patch) | |
tree | 73a04b9bc030bcf2da4c047a93fdf896180544cb /src/components/TimerPage | |
parent | cd76594392b038c49d437f374db3a3665cbbf92f (diff) | |
parent | 002a8c257bb0b78d313ccc30c289534941c9e008 (diff) | |
download | chrono-cube-ui-4931f205e1250c649b3a48b96a7823a9d52615ff.tar.gz |
Merge pull request #29 from Eug-VS/timer-page
Markup Timer page
Diffstat (limited to 'src/components/TimerPage')
-rw-r--r-- | src/components/TimerPage/TimerPage.js | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/src/components/TimerPage/TimerPage.js b/src/components/TimerPage/TimerPage.js new file mode 100644 index 0000000..f304b46 --- /dev/null +++ b/src/components/TimerPage/TimerPage.js @@ -0,0 +1,58 @@ +import React from 'react'; + +import { Grid, Box } from "@material-ui/core"; +import { makeStyles } from "@material-ui/core/styles"; + +import Timer from "../Timer/Timer"; +import SolutionCard from "../SolutionCard/SolutionCard"; + +import { post } from '../../requests'; + + +const useStyles = makeStyles(theme => ({ + root: { + display: 'flex', + justifyContent: 'space-between', + padding: theme.spacing(5, 4, 4, 4), + }, +})); + +const TimerPage = ({ recentSolutions, setRecentSolutions }) => { + const classes = useStyles(); + + const user = { + id: null, + username: 'anonymous', + }; + + const registerResult = result => { + const solution = { author_id: user.id, result }; + post('solutions/', solution).then(response => { + setRecentSolutions([response.data].concat(recentSolutions)); + }); + }; + + const removeSolution = (id) => { + setRecentSolutions(recentSolutions.filter((solution => solution.id !== id))); + }; + + return ( + <Box className={classes.root}> + <Grid container direction="row" justify="space-around" spacing={8}> + <Grid item xs={6}> + <Timer registerResult={registerResult} style={{ position: 'fixed' }}/> + </Grid> + <Grid item xs={4} container direction="column" spacing={5}> + {recentSolutions.slice(0, 3).map(solution => ( + <Grid item key={solution.id}> + <SolutionCard data={solution} removeThisCard={removeSolution}/> + </Grid> + ))} + </Grid> + </Grid> + </Box> + ); +}; + + +export default TimerPage; |