From c06bce7fdab23e52d33636e3585c86d48c0bfa91 Mon Sep 17 00:00:00 2001 From: Eug-VS Date: Sun, 12 Jan 2020 14:16:26 +0300 Subject: Markup initial Profile page with empty form --- src/index.js | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) (limited to 'src/index.js') diff --git a/src/index.js b/src/index.js index 0c3d415..f90c39a 100644 --- a/src/index.js +++ b/src/index.js @@ -10,6 +10,7 @@ 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"; const App = () => { @@ -28,19 +29,17 @@ const App = () => { /> ); + case 'profile': + return ; + case 'scoreboard': - return (); + return ; case 'contribute': - return (); + return ; default: - return ( -

- This text is rendered outside of Header component, but - interacting with Header can influence content of this page! -

- ) + return ; } }; -- cgit v1.2.3 From 3ef3cb7f0b25a448e81e5b81738758f4545337cc Mon Sep 17 00:00:00 2001 From: Eug-VS Date: Sun, 12 Jan 2020 15:35:46 +0300 Subject: Implement Registration component --- src/index.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'src/index.js') diff --git a/src/index.js b/src/index.js index f90c39a..4db99cf 100644 --- a/src/index.js +++ b/src/index.js @@ -16,6 +16,7 @@ import Profile from "./pages/Profile/Profile"; const App = () => { const [page, setPage] = useState('app'); + const [user, setUser] = useState({ username: 'anonymous', id: null }); const [recentSolutions, setRecentSolutions] = useState([]); const Page = ({ page }) => { @@ -23,6 +24,7 @@ const App = () => { case 'app': return ( { ); case 'profile': - return ; + return ; case 'scoreboard': return ; -- cgit v1.2.3 From 0de06228f4b5e482b6f73230210225b332f0a2ff Mon Sep 17 00:00:00 2001 From: Eug-VS Date: Sun, 12 Jan 2020 16:02:25 +0300 Subject: Store user data in localStorage (optionally) --- src/index.js | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'src/index.js') diff --git a/src/index.js b/src/index.js index 4db99cf..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'; @@ -12,6 +12,8 @@ import Scoreboard from "./pages/Scoreboard/Scoreboard"; import Contribute from "./pages/Contribute/Contribute"; import Profile from "./pages/Profile/Profile"; +import { get } from "./requests"; + const App = () => { @@ -19,6 +21,15 @@ const 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': -- cgit v1.2.3