diff options
author | Eug-VS <eug-vs@keemail.me> | 2020-01-12 16:02:25 +0300 |
---|---|---|
committer | Eug-VS <eug-vs@keemail.me> | 2020-01-12 18:11:45 +0300 |
commit | 0de06228f4b5e482b6f73230210225b332f0a2ff (patch) | |
tree | fc73b4e0703e5d5b96290cfa22d71d57129d9c31 /src/index.js | |
parent | 3ef3cb7f0b25a448e81e5b81738758f4545337cc (diff) | |
download | chrono-cube-ui-0de06228f4b5e482b6f73230210225b332f0a2ff.tar.gz |
Store user data in localStorage (optionally)
Diffstat (limited to 'src/index.js')
-rw-r--r-- | src/index.js | 13 |
1 files changed, 12 insertions, 1 deletions
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': |