diff options
author | Eugene <eug-vs@keemail.me> | 2020-01-12 15:18:00 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-01-12 15:18:00 +0000 |
commit | 8b163ac33a8bb7fc77f934d20ab8454758abf0d7 (patch) | |
tree | a3edf615afdc83d364d58b84065017fae7fb5e98 /src/index.js | |
parent | d131fe1c40da4faf8fe850994d000263f867c9d6 (diff) | |
parent | fff9eae8022e1e3bb88884a47bfd4153b089f444 (diff) | |
download | chrono-cube-ui-8b163ac33a8bb7fc77f934d20ab8454758abf0d7.tar.gz |
Merge pull request #35 from Eug-VS/profile-window
Markup Profile page
Diffstat (limited to 'src/index.js')
-rw-r--r-- | src/index.js | 30 |
1 files changed, 21 insertions, 9 deletions
diff --git a/src/index.js b/src/index.js index 0c3d415..6563c60 100644 --- a/src/index.js +++ b/src/index.js @@ -1,4 +1,4 @@ -import React, { useState } from 'react'; +import React, { useState, useEffect } from 'react'; import ReactDOM from 'react-dom'; import CssBaseline from '@material-ui/core/CssBaseline'; @@ -10,37 +10,49 @@ import Header from './components/Header/Header'; 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 { get } from "./requests"; const App = () => { const [page, setPage] = useState('app'); + const [user, setUser] = useState({ username: 'anonymous', id: null }); const [recentSolutions, setRecentSolutions] = useState([]); + useEffect(() => { + const userId = +localStorage.getItem('userId'); + if (userId) { + get('users/').then(response => { + setUser(response.data.filter(user => user.id === +userId)[0]); + }); + } + }, []); + const Page = ({ 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 />); + return <Scoreboard />; case 'contribute': - return (<Contribute />); + return <Contribute />; default: - return ( - <p> - This text is rendered outside of <code>Header</code> component, but - interacting with <code>Header</code> can influence content of this page! - </p> - ) + return <Contribute />; } }; |