blob: 1323d97cdd9ea7584401a90e7b6f2010a7764c60 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
|
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 { Button, makeStyles } from '@material-ui/core';
const useStyles = makeStyles(theme => ({
primary: {
padding: theme.spacing(4),
},
cell: {
padding: theme.spacing(5),
},
}));
const Timer = ({ user, recentSolutions, setRecentSolutions, setPage }) => {
const classes = useStyles();
const registerResult = result => {
const solution = { author_id: user.id, result };
post('solutions/', solution).then(response => {
setRecentSolutions([response.data].concat(recentSolutions));
});
};
const handleLearnMore = () => {
setPage('contribute');
};
const handleLogin = () => {
setPage('profile');
};
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!">
<p>
ChronoCube is a professional speedcubing timer.
Share your results publicly - let everyone see your progress and
achievements!
Every speedcuber will benefit
from using it - both amateur and professional!
</p>
<Button variant="contained" color="secondary" onClick={handleLearnMore}> Learn more </Button>
</ContentSection>
{user.id === null &&
<ContentSection sectionName="Log into an account">
<p> Tell us your name so we can track your progress</p>
<Button variant="contained" color="secondary" onClick={handleLogin} size="large"> Login </Button>
</ContentSection>
}
<TimerButton registerResult={registerResult} />
</div>
</Window>
<Window type="secondary" name="Recent solutions">
<SmartList
itemSize={270}
itemCount={recentSolutions.length}
renderItem={renderItem}
/>
</Window>
</>
);
};
export default Timer;
|