diff options
author | Eugene Sokolov <eug-vs@keemail.me> | 2020-03-21 17:59:48 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-03-21 17:59:48 +0300 |
commit | e89a7a79622d25561dc80a8489ae1f6022aebd73 (patch) | |
tree | e115938b26ee6019b4c349f52bd98fc34a4575e9 /src/index.tsx | |
parent | fe750a9aadfb451b9537bb3cdd79581ef5120c07 (diff) | |
parent | 7f8ab6802c68c46f988ef012fdc88b09e43a9e54 (diff) | |
download | chrono-cube-ui-e89a7a79622d25561dc80a8489ae1f6022aebd73.tar.gz |
Merge pull request #48 from eug-vs/typescript
Migrate project to Typescript
Diffstat (limited to 'src/index.tsx')
-rw-r--r-- | src/index.tsx | 88 |
1 files changed, 88 insertions, 0 deletions
diff --git a/src/index.tsx b/src/index.tsx new file mode 100644 index 0000000..360ca89 --- /dev/null +++ b/src/index.tsx @@ -0,0 +1,88 @@ +import React, { useState, useEffect } from 'react'; +import ReactDOM from 'react-dom'; + +import { + BenzinThemeProvider, + Header, +} from 'react-benzin'; +import { User, Solution } from './types'; + +import 'typeface-roboto'; + +import Timer from './pages/Timer/Timer'; +import Scoreboard from './pages/Scoreboard/Scoreboard'; +import Contribute from './pages/Contribute/Contribute'; +import Profile from './pages/Profile/Profile'; + +import TimerIcon from '@material-ui/icons/Timer'; +import AccountCircleIcon from '@material-ui/icons/AccountCircle'; +import AssignmentIcon from '@material-ui/icons/Assignment'; +import GitHubIcon from '@material-ui/icons/GitHub'; + +import { get } from './requests'; + + +const App: React.FC = () => { + const [page, setPage] = useState<string>('app'); + const [user, setUser] = useState<User>({ username: 'anonymous', id: null }); + const [recentSolutions, setRecentSolutions] = useState<Solution[]>([]); + + const headerContents = { + app: (<TimerIcon />), + profile: (<AccountCircleIcon />), + scoreboard: (<AssignmentIcon />), + contribute: (<GitHubIcon />), + }; + + useEffect(() => { + const userId = localStorage.getItem('userId'); + if (userId) { + get('users/').then(response => { + setUser(response.data.filter((user: User) => user.id === +userId)[0]); + }); + } + }, []); + + const Page: React.FC<{ page: string }> = ({ page }) => { + switch (page) { + case 'app': + return ( + <Timer + user={user} + recentSolutions={recentSolutions} + setRecentSolutions={setRecentSolutions} + setPage={setPage} + /> + ); + + case 'profile': + return <Profile user={user} setUser={setUser} />; + + case 'scoreboard': + return <Scoreboard />; + + case 'contribute': + return <Contribute />; + + default: + return <Contribute />; + } + }; + + return ( + <BenzinThemeProvider> + <Header + logo={{ + title: 'ChronoCube', + icon: null + }} + contents={headerContents} + page={page} + setPage={setPage}/> + <Page page={page} /> + </BenzinThemeProvider> + ); +}; + +document.body.style.overflow = 'hidden'; +ReactDOM.render(<App />, document.getElementById('root')); |