aboutsummaryrefslogtreecommitdiff
path: root/src/pages/Timer/Timer.js
diff options
context:
space:
mode:
authorEug-VS <eug-vs@keemail.me>2020-01-11 17:56:38 +0300
committerEug-VS <eug-vs@keemail.me>2020-01-11 17:58:19 +0300
commitb2fe1b816044b8630f570c04c884c8ffcf3e3e61 (patch)
treed2a33cea442a05e626fc74e05f29b8e3c7f94bdc /src/pages/Timer/Timer.js
parentd517398707f74c670d47ed0a277ba328e531579e (diff)
downloadchrono-cube-ui-b2fe1b816044b8630f570c04c884c8ffcf3e3e61.tar.gz
Improve names, getPageComponent() --> <Page />
Remove 'Page' word from page-components, since they are all now located in the pages/ folder.
Diffstat (limited to 'src/pages/Timer/Timer.js')
-rw-r--r--src/pages/Timer/Timer.js76
1 files changed, 76 insertions, 0 deletions
diff --git a/src/pages/Timer/Timer.js b/src/pages/Timer/Timer.js
new file mode 100644
index 0000000..4b5925f
--- /dev/null
+++ b/src/pages/Timer/Timer.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 TimerButton from "./TimerButton/TimerButton";
+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 Timer = ({ 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>
+ <TimerButton registerResult={registerResult} />
+ </div>
+ </Window>
+ <Window type="secondary" name="Recent solutions">
+ <SmartList
+ itemSize={270}
+ itemCount={recentSolutions.length}
+ renderItem={renderItem}
+ />
+ </Window>
+ </>
+ );
+};
+
+
+export default Timer;