diff options
author | Eug-VS <eug-vs@keemail.me> | 2020-01-11 17:44:46 +0300 |
---|---|---|
committer | Eug-VS <eug-vs@keemail.me> | 2020-01-11 17:44:46 +0300 |
commit | 31da3a746ce7d86ade32b60acb68365670d97726 (patch) | |
tree | 90041e4a485179f203202f134dff5994601edf66 /src/pages/TimerPage/TimerPage.js | |
parent | e78ecf560a0c6f4cf59a3c4341884996464c7923 (diff) | |
download | chrono-cube-ui-31da3a746ce7d86ade32b60acb68365670d97726.tar.gz |
Move all pages to separate folder
Diffstat (limited to 'src/pages/TimerPage/TimerPage.js')
-rw-r--r-- | src/pages/TimerPage/TimerPage.js | 76 |
1 files changed, 76 insertions, 0 deletions
diff --git a/src/pages/TimerPage/TimerPage.js b/src/pages/TimerPage/TimerPage.js new file mode 100644 index 0000000..591eb7b --- /dev/null +++ b/src/pages/TimerPage/TimerPage.js @@ -0,0 +1,76 @@ +import React from 'react'; + +import { post } from '../../requests'; + +import Window from "../../components/Window/Window"; +import ContentSection from "../../components/ContentSection/ContentSection"; +import Timer from "./Timer/Timer"; +import SmartList from "../../components/SmartList/SmartList"; +import SolutionCard from "../../components/SolutionCard/SolutionCard"; + +import { Typography, makeStyles } from "@material-ui/core"; + + +const useStyles = makeStyles(theme => ({ + primary: { + padding: theme.spacing(4), + }, + cell: { + padding: theme.spacing(5), + }, +})); + +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))); + }; + + const renderItem = ({ index, style }) => { + const solution = recentSolutions[index]; + return ( + <div style={style} className={classes.cell}> + <SolutionCard data={solution} removeThisCard={removeSolution} /> + </div> + ); + }; + + return ( + <> + <Window type="primary"> + <div className={classes.primary}> + <ContentSection sectionName="Welcome to ChronoCube!"> + <Typography> + Here is some text about how cool this application is, why you should use it + and how to make it better! + </Typography> + </ContentSection> + <Timer registerResult={registerResult} /> + </div> + </Window> + <Window type="secondary" name="Recent solutions"> + <SmartList + itemSize={270} + itemCount={recentSolutions.length} + renderItem={renderItem} + /> + </Window> + </> + ); +}; + + +export default TimerPage; |