aboutsummaryrefslogtreecommitdiff
path: root/src/index.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/index.js')
-rw-r--r--src/index.js13
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':