From 9e2132cd54e5f5e6b85c7d949ac982cb95566027 Mon Sep 17 00:00:00 2001 From: eug-vs Date: Sat, 21 Mar 2020 16:04:26 +0300 Subject: chore: migrate Timer page to Typescript :label: --- src/pages/Timer/Timer.tsx | 102 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 102 insertions(+) create mode 100644 src/pages/Timer/Timer.tsx (limited to 'src/pages/Timer/Timer.tsx') diff --git a/src/pages/Timer/Timer.tsx b/src/pages/Timer/Timer.tsx new file mode 100644 index 0000000..3ceb674 --- /dev/null +++ b/src/pages/Timer/Timer.tsx @@ -0,0 +1,102 @@ +import React from 'react'; + +import { post } from '../../requests'; + +import { + Window, + ContentSection, + SmartList, +} from 'react-benzin'; +import { User, Solution, RenderPropTypes } from '../../types'; + +import TimerButton from './TimerButton'; +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), + }, +})); + + +interface PropTypes { + user: User; + recentSolutions: Solution[]; + setRecentSolutions: (newRecentSolutions: Solution[]) => void; + setPage: (newPage: string) => void; +} + + +const Timer: React.FC = ({ user, recentSolutions, setRecentSolutions, setPage }) => { + const classes = useStyles(); + + const registerResult = (result: string): void => { + const solution = { author_id: user.id, result }; + post('solutions/', solution).then(response => { + setRecentSolutions([response.data].concat(recentSolutions)); + }); + }; + + const handleLearnMore = (): void => { + setPage('contribute'); + }; + + const handleLogin = (): void => { + setPage('profile'); + }; + + const removeSolution = (id: number): void => { + setRecentSolutions(recentSolutions.filter((solution => solution.id !== id))); + }; + + const renderItem: React.FC = ({ index, style }) => { + const solution = recentSolutions[index]; + return ( +
+ +
+ ); + }; + + return ( + <> + +
+ +

+ 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! +

+ +
+ {user.id === null && + +

Tell us your name so we can track your progress

+ +
+ } + +
+
+ + + + + ); +}; + + +export default Timer; -- cgit v1.2.3 From 0f6c4e7e4d44314707535e2d7e3aba7b638cd2dd Mon Sep 17 00:00:00 2001 From: eug-vs Date: Sat, 21 Mar 2020 16:11:31 +0300 Subject: fix: add more missing types :ok_hand: --- src/pages/Timer/Timer.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/pages/Timer/Timer.tsx') diff --git a/src/pages/Timer/Timer.tsx b/src/pages/Timer/Timer.tsx index 3ceb674..a890815 100644 --- a/src/pages/Timer/Timer.tsx +++ b/src/pages/Timer/Timer.tsx @@ -37,7 +37,7 @@ const Timer: React.FC = ({ user, recentSolutions, setRecentSolutions, const classes = useStyles(); const registerResult = (result: string): void => { - const solution = { author_id: user.id, result }; + const solution = { 'author_id': user.id, result }; post('solutions/', solution).then(response => { setRecentSolutions([response.data].concat(recentSolutions)); }); -- cgit v1.2.3