From 2677793b2844d7e792e3edaa070eccc06d55ecec Mon Sep 17 00:00:00 2001 From: Felix Albrigtsen Date: Sat, 23 Apr 2022 15:17:07 +0200 Subject: [PATCH] =?UTF-8?q?ny=20kl=C3=A6bb?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/client/src/FrontPage.js | 92 ++++++++++++++++++++++------------- src/client/src/ProfilePage.js | 10 +--- 2 files changed, 60 insertions(+), 42 deletions(-) diff --git a/src/client/src/FrontPage.js b/src/client/src/FrontPage.js index 2c027fe..445d84f 100644 --- a/src/client/src/FrontPage.js +++ b/src/client/src/FrontPage.js @@ -200,48 +200,72 @@ function Home() { ); } -class LoginManager { - user = { - name: "", - email: "", - googleId: "", - asuraId: -1, - isManager: false - }; - checkLogin() { - fetch(process.env.REACT_APP_API_URL + `/users/getSavedUser`) - .then(res => res.json()) - .then(data => { - if (data.status !== "OK") { - console.error(data.data); - return; - } - console.log(data); - this.user = data.data; - return this.user; - }) - .catch((err) => console.log(err.message)); - } +// class LoginManager { +// checkLogin() { +// fetch(process.env.REACT_APP_API_URL + `/users/getSavedUser`) +// .then(res => res.json()) +// .then(data => { +// if (data.status !== "OK") { +// console.error(data.data); +// return; +// } +// console.log(data); +// setUser(data.data); +// return user; +// }) +// .catch((err) => console.log(err.message)); +// } - isLoggedIn() { - let loggedIn = this.user.googleId !== "" && this.user.asuraId !== -1; - console.log(loggedIn); - return loggedIn; - } - isManager() { - return this.isLoggedIn() && this.user.isManager; - } -} +// isLoggedIn() { +// let loggedIn = user.googleId !== "" && user.asuraId !== -1; +// console.log(loggedIn); +// return loggedIn; +// } +// isManager() { +// return this.isLoggedIn() && user.isManager; +// } +// } -let login = new LoginManager(); -login.checkLogin(); +// let login = new LoginManager(); +// login.checkLogin(); let showSuccess = (message) => {}; let showError = (message) => {}; export default function App() { + const [user, setUser] = React.useState({}); + let checkLogin = () => { + fetch(process.env.REACT_APP_API_URL + `/users/getSavedUser`) + .then(res => res.json()) + .then(data => { + if (data.status !== "OK") { + setUser({ + isManager: false, + isLoggedIn: false + }); + console.error(data.data); + return; + } + console.log(data); + let u = data.data; + u.isLoggedIn = true; + setUser(u); + }) + .catch((err) => { + console.log(err.message); + setUser({ + isManager: false, + isLoggedIn: false + }); + }); + } + + React.useEffect(() => { + checkLogin(); + }, []); + const [openError, setOpenError] = React.useState(false); const [errorMessage, setErrorMessage] = React.useState(""); showError = (message) => { @@ -269,7 +293,7 @@ export default function App() { } /> } /> } /> - } /> + } /> } /> diff --git a/src/client/src/ProfilePage.js b/src/client/src/ProfilePage.js index 5ca3dcd..17298a1 100644 --- a/src/client/src/ProfilePage.js +++ b/src/client/src/ProfilePage.js @@ -5,17 +5,11 @@ import ErrorSnackbar from "./components/ErrorSnackbar"; import { Button, TextField, Stack, InputLabel, Select, Container, Slider, Paper, Box, Grid, Typography } from '@mui/material'; export default function ProfilePage(props) { - const [loggedIn, setLoggedIn] = React.useState(props.login.isLoggedIn()); - React.useEffect(() => { - setLoggedIn(props.login.isLoggedIn()); - }, [props.login]); - - - let user = props.login.user; + let user = props.user; return (<> - {loggedIn ? <> + {user.isLoggedIn ? <>

Your profile