From c61b1a6492fc449e54ba7f4655b1bde6d9b64e37 Mon Sep 17 00:00:00 2001 From: Rohan Fowler-Harper <88605753+rohan-fowlerharper@users.noreply.github.com> Date: Thu, 9 Dec 2021 08:41:31 +1300 Subject: [PATCH] add overall profile rating --- client/components/UserCompanyTile.jsx | 4 ++ client/pages/UserProfile.jsx | 91 ++++++++++++++++++++++++--- 2 files changed, 86 insertions(+), 9 deletions(-) diff --git a/client/components/UserCompanyTile.jsx b/client/components/UserCompanyTile.jsx index 831da45..827a5b9 100644 --- a/client/components/UserCompanyTile.jsx +++ b/client/components/UserCompanyTile.jsx @@ -63,6 +63,7 @@ function UserCompanyTile ({ stonk }) { rating={stonk.totalScore} max={3000} mb={4} + level={stonk.totalLevel} /> diff --git a/client/pages/UserProfile.jsx b/client/pages/UserProfile.jsx index 12d04bd..ec436c7 100644 --- a/client/pages/UserProfile.jsx +++ b/client/pages/UserProfile.jsx @@ -1,5 +1,5 @@ import React, { useEffect, useState } from 'react' -import { VStack, Image, Text, Button, Link, Grid } from '@chakra-ui/react' +import { VStack, Image, Text, Button, Link, Grid, Flex, Heading } from '@chakra-ui/react' import { useAuth0, withAuthenticationRequired } from '@auth0/auth0-react' import { getUserStonks } from '../apis/stonks' @@ -7,11 +7,27 @@ import { getUserStonks } from '../apis/stonks' // import EditProfile from '../components/EditProfile' import UserCompanyTile from '../components/UserCompanyTile' import RegularLayout from '../layouts/RegularLayout' +import Rating from '../components/Rating' +import RatingBar from '../components/RatingBar' function UserProfile () { const { user, isAuthenticated, getAccessTokenSilently } = useAuth0() const [userStonks, setUserStonks] = useState([]) + const avgRatings = { + total: _avgRating(userStonks, 'totalScore'), + environment: _avgRating(userStonks, 'environmentScore'), + social: _avgRating(userStonks, 'socialScore'), + governance: _avgRating(userStonks, 'governanceScore') + } + + const avgLevels = { + total: _avgLevel(avgRatings.total, 3000), + environment: _avgLevel(avgRatings.environment, 1000), + social: _avgLevel(avgRatings.social, 1000), + governance: _avgLevel(avgRatings.governance, 1000) + } + useEffect(() => { (async () => { try { @@ -28,15 +44,60 @@ function UserProfile () { {isAuthenticated ? ( <> - - Profile - Welcome, {user.name}! - - + + + + {userStonks && userStonks.length > 0 && ( + + Your Portfolio: + + + + + + + + + + + + )} + acc + stonk[key], 0) / stonks.length +} + +function _avgLevel (rating, max) { + const value = Math.floor(rating / max * 100) + if (value < 20) return 'Low' + if (value < 40) return 'Medium' + if (value < 60) return 'High' + else return 'Excellent' +}