From bd176e232926653584abf8e4b80d2f839f842cc5 Mon Sep 17 00:00:00 2001 From: mattyl006 Date: Wed, 30 Nov 2022 17:36:20 +0100 Subject: [PATCH] get user request and bold current user in Table logic --- src/App.js | 3 -- src/api/getUser.js | 14 +++++++ .../Leaderboard/Leaderboard.js | 4 ++ src/components/specific_challenge/Submit.js | 4 +- src/components/specific_challenge/Table.js | 37 ++++++++++++++----- 5 files changed, 49 insertions(+), 13 deletions(-) create mode 100644 src/api/getUser.js diff --git a/src/App.js b/src/App.js index bf92e0f..bde66cd 100644 --- a/src/App.js +++ b/src/App.js @@ -42,9 +42,6 @@ const App = () => { }); const popUpMessageHandler = (header, message) => { - console.log('elo'); - console.log(header); - console.log(message); setPopUpHeader(header); setPopUpMessage(message); }; diff --git a/src/api/getUser.js b/src/api/getUser.js new file mode 100644 index 0000000..5e52051 --- /dev/null +++ b/src/api/getUser.js @@ -0,0 +1,14 @@ +import {API} from '../utils/globals'; + +const getUser = (setDataState, setLoadingState) => { + fetch(`${API}/user-info`) + .then(response => response.text()) + .then(data => { + console.log(data); + setDataState(data); + if (setLoadingState) + setLoadingState(false); + }); +}; + +export default getUser; \ No newline at end of file diff --git a/src/components/specific_challenge/Leaderboard/Leaderboard.js b/src/components/specific_challenge/Leaderboard/Leaderboard.js index 87279d1..4597604 100644 --- a/src/components/specific_challenge/Leaderboard/Leaderboard.js +++ b/src/components/specific_challenge/Leaderboard/Leaderboard.js @@ -11,6 +11,7 @@ import {CALC_PAGES, EVALUATIONS_FORMAT, RENDER_WHEN} from '../../../utils/global import Search from '../../generic/Search'; import Pager from '../../generic/Pager'; import Loading from '../../generic/Loading'; +import getUser from '../../../api/getUser'; const Leaderboard = (props) => { const [entriesFromApi, setEntriesFromApi] = React.useState([]); @@ -21,6 +22,7 @@ const Leaderboard = (props) => { const [entriesSorted, setEntriesSorted] = React.useState(false); const [whenSorted, setWhenSorted] = React.useState(false); const [scoreSorted, setScoreSorted] = React.useState(false); + const [user, setUser] = React.useState(''); React.useEffect(() => { challengeDataRequest(props.challengeName); @@ -28,6 +30,7 @@ const Leaderboard = (props) => { const challengeDataRequest = (challengeName) => { getChallengeLeaderboard(setEntriesFromApi, challengeName); + getUser(setUser); getChallengeLeaderboard(setEntries, challengeName, setLoading); }; @@ -156,6 +159,7 @@ const Leaderboard = (props) => { { }; const challengeSubmissionSubmit = () => { - challengeSubmission(props.challengeName, repoUrl, repoBranch, description).then(r => console.log(r)); + challengeSubmission(props.challengeName, repoUrl, repoBranch, description) + .then((response) => response.text()) + .then((data) => console.log(data)); props.popUpMessageHandler('Submit success!', 'Check your entries.'); }; diff --git a/src/components/specific_challenge/Table.js b/src/components/specific_challenge/Table.js index 66f837f..02bbab6 100644 --- a/src/components/specific_challenge/Table.js +++ b/src/components/specific_challenge/Table.js @@ -60,6 +60,33 @@ const Table = (props) => { ); }; + const rowRender = (elem) => { + if (elem.submitter === props.user) { + return ( + props.staticColumnElements.map((elemName, i) => { + return ( + + {elemName.format ? elemName.format(elem[elemName.name]) : elem[elemName.name]} + + ); + }) + ); + } + return ( + props.staticColumnElements.map((elemName, i) => { + return ( + + {elemName.format ? elemName.format(elem[elemName.name]) : elem[elemName.name]} + + ); + }) + ); + }; + const desktopRender = () => { const n = (props.pageNr - 1) * (ELEMENTS_PER_PAGE * 2); let elementsToMap = props.elements.slice(n, n + (ELEMENTS_PER_PAGE * 2)); @@ -104,15 +131,7 @@ const Table = (props) => { backgroundColor={index % 2 === 1 ? theme.colors.dark01 : 'transparent'} gridTemplateColumns={props.gridTemplateColumns} gridGap='20px' position='relative' width='100%' padding='4px'> - {props.staticColumnElements.map((elemName, i) => { - return ( - - {elemName.format ? elemName.format(elem[elemName.name]) : elem[elemName.name]} - - ); - })} + {rowRender(elem)} {props.headerElements ? metricsRender(elem) : ''} );