diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/index.tsx | 7 | ||||
-rw-r--r-- | src/pages/Scoreboard/Scoreboard.tsx (renamed from src/pages/Scoreboard/Scoreboard.js) | 16 | ||||
-rw-r--r-- | src/types.d.ts | 12 |
3 files changed, 26 insertions, 9 deletions
diff --git a/src/index.tsx b/src/index.tsx index eb43b7e..360ca89 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -5,6 +5,7 @@ import { BenzinThemeProvider, Header, } from 'react-benzin'; +import { User, Solution } from './types'; import 'typeface-roboto'; @@ -20,15 +21,11 @@ import GitHubIcon from '@material-ui/icons/GitHub'; import { get } from './requests'; -interface User { - username: string; - id: number | null; -} const App: React.FC = () => { const [page, setPage] = useState<string>('app'); const [user, setUser] = useState<User>({ username: 'anonymous', id: null }); - const [recentSolutions, setRecentSolutions] = useState([]); + const [recentSolutions, setRecentSolutions] = useState<Solution[]>([]); const headerContents = { app: (<TimerIcon />), diff --git a/src/pages/Scoreboard/Scoreboard.js b/src/pages/Scoreboard/Scoreboard.tsx index 47c0899..c6826d2 100644 --- a/src/pages/Scoreboard/Scoreboard.js +++ b/src/pages/Scoreboard/Scoreboard.tsx @@ -3,6 +3,7 @@ import React, { useEffect, useState } from 'react'; import { makeStyles } from '@material-ui/core/styles'; import { Window, SmartList } from 'react-benzin'; +import { Solution } from '../../types'; import SolutionCard from '../../components/SolutionCard/SolutionCard'; import Loading from '../../components/Loading/Loading'; @@ -22,9 +23,16 @@ const useStyles = makeStyles(theme => ({ } })); -const Scoreboard = () => { + +interface RenderPropTypes { + index: number; + style: React.CSSProperties; +} + + +const Scoreboard: React.FC = () => { const classes = useStyles(); - const [solutions, setSolutions] = useState([]); + const [solutions, setSolutions] = useState<Solution[]>([]); const updateSolutions = () => { get('scoreboard/').then(response => { @@ -32,7 +40,7 @@ const Scoreboard = () => { }); }; - const removeSolution = id => { + const removeSolution = (id: number) => { updateSolutions(); }; @@ -40,7 +48,7 @@ const Scoreboard = () => { setTimeout(updateSolutions, 300); }, []); - const renderItem = ({ index, style }) => { + const renderItem: React.FC<RenderPropTypes> = ({ index, style }) => { return ( <div style={style} className={classes.cell}> <SolutionCard data={solutions[index]} removeThisCard={removeSolution}/> diff --git a/src/types.d.ts b/src/types.d.ts new file mode 100644 index 0000000..cfc60bc --- /dev/null +++ b/src/types.d.ts @@ -0,0 +1,12 @@ +export interface User { + username: string; + id: number | null; +} + +export interface Solution { + id: number; + result: string; + date: string; + author: User; +} + |