diff --git a/src/components/Profile.tsx b/src/components/Profile.tsx index 5beca9e..eebcd1f 100644 --- a/src/components/Profile.tsx +++ b/src/components/Profile.tsx @@ -1,13 +1,13 @@ -import React, { useState, useEffect } from 'react'; -import { API_ENDPOINT } from '../api/api'; -import { makeStyles } from '@material-ui/core/styles'; +import Button from '@material-ui/core/Button'; import Card from '@material-ui/core/Card'; import CardActionArea from '@material-ui/core/CardActionArea'; import CardActions from '@material-ui/core/CardActions'; import CardContent from '@material-ui/core/CardContent'; -import CardMedia from '@material-ui/core/CardMedia'; -import Button from '@material-ui/core/Button'; +import { makeStyles } from '@material-ui/core/styles'; import Typography from '@material-ui/core/Typography'; +import { useContext, useEffect, useState } from 'react'; +import { API_ENDPOINT } from '../api/api'; +import AuthenticationContext from './AuthenticationContext'; const useStyles = makeStyles({ root: { @@ -17,13 +17,10 @@ const useStyles = makeStyles({ height: 140, }, }); + const Profile = () => { - const [state, setState] = useState({ - user: { - username: 'HyperionLegion', - }, - groups: [], - }); + const { user, isLoggedIn } = useContext(AuthenticationContext); + const [groups, setGroups] = useState([]); const [pools, setPools] = useState([ { id: 1, @@ -76,16 +73,6 @@ const Profile = () => { ]); const classes = useStyles(); - const callAPI = () => { - fetch(`${process.env.REACT_APP_API_ENDPOINT}/profile/`) - .then((response) => response.json()) - .then((data) => { - if (data !== undefined) { - setState(data); - } - }); - }; - useEffect(() => { console.log(process.env); fetch(`${API_ENDPOINT}/my_pools`) @@ -96,6 +83,11 @@ const Profile = () => { } }); }, []); + + if (!user) { + return

Please Sign In

; + } + return (
{ >

Profile

-
+

- {state.user.username}'s Pools + {user.username}'s Pools

{pools.map((pool) => {