From 782627a920c32ccdd1c86a2ae532b05c056ab4ba Mon Sep 17 00:00:00 2001 From: mattyl006 Date: Tue, 15 Nov 2022 17:29:09 +0100 Subject: [PATCH] correct sorting values in Table --- src/api/getMyEntries.js | 8 +++++++- .../sections/Leaderboard/Leaderboard.js | 5 ++--- src/components/sections/MyEntries.js | 18 +++++++++++------- 3 files changed, 20 insertions(+), 11 deletions(-) diff --git a/src/api/getMyEntries.js b/src/api/getMyEntries.js index b1f6454..0763fd6 100644 --- a/src/api/getMyEntries.js +++ b/src/api/getMyEntries.js @@ -1,7 +1,7 @@ import {API} from '../utils/globals'; import KeyCloakService from '../services/KeyCloakService'; -const getMyEntries = (challengeName, setDataOriginalState, setDataState, setLoadingState) => { +const getMyEntries = (challengeName, setDataOriginalState, setDataState, setLoadingState, setScoreSorted) => { fetch(`${API}/challenge-my-submissions/${challengeName}`, { headers: {'Authorization': `Bearer ${KeyCloakService.getToken()}`} }) @@ -10,6 +10,7 @@ const getMyEntries = (challengeName, setDataOriginalState, setDataState, setLoad setDataOriginalState(data); let item = {}; let result = []; + let initSetScoreSorted = []; let tests = data.tests; for (let submission of data.submissions) { for (let evaluation of submission.evaluations) { @@ -41,6 +42,11 @@ const getMyEntries = (challengeName, setDataOriginalState, setDataState, setLoad result.push(item); item = {}; } + // eslint-disable-next-line no-unused-vars + for (let _ of tests) { + initSetScoreSorted.push(false); + } + setScoreSorted(initSetScoreSorted); setDataState(result); setLoadingState(false); }); diff --git a/src/components/sections/Leaderboard/Leaderboard.js b/src/components/sections/Leaderboard/Leaderboard.js index 70774bf..944478a 100644 --- a/src/components/sections/Leaderboard/Leaderboard.js +++ b/src/components/sections/Leaderboard/Leaderboard.js @@ -90,10 +90,10 @@ const Leaderboard = (props) => { switch (elem) { case 'submitter': if (submitterSorted) { - newEntries = newEntries.sort((a, b) => (a.submitter > b.submitter) ? 1 : ((b.submitter > a.submitter) ? -1 : 0)); + newEntries = newEntries.sort((a, b) => (a.submitter < b.submitter) ? 1 : ((b.submitter < a.submitter) ? -1 : 0)); setSubmitterSorted(false); } else { - newEntries = newEntries.sort((a, b) => (a.submitter < b.submitter) ? 1 : ((b.submitter < a.submitter) ? -1 : 0)); + newEntries = newEntries.sort((a, b) => (a.submitter > b.submitter) ? 1 : ((b.submitter > a.submitter) ? -1 : 0)); setSubmitterSorted(true); } break; @@ -126,7 +126,6 @@ const Leaderboard = (props) => { } break; } - console.log(newEntries); setEntries(newEntries); }; diff --git a/src/components/sections/MyEntries.js b/src/components/sections/MyEntries.js index 67fce0a..e2242c3 100644 --- a/src/components/sections/MyEntries.js +++ b/src/components/sections/MyEntries.js @@ -16,7 +16,7 @@ const MyEntries = (props) => { const [loading, setLoading] = React.useState(true); const [pageNr, setPageNr] = React.useState(1); const [whenSorted, setWhenSorted] = React.useState(false); - const [scoreSorted, setScoreSorted] = React.useState(false); + const [scoresSorted, setScoresSorted] = React.useState([]); /* eslint-disable */ React.useEffect(() => { @@ -62,7 +62,7 @@ const MyEntries = (props) => { }; const challengesRequest = () => { - getMyEntries(props.challengeName, setMyEntriesFromAPI, setMyEntries, setLoading); + getMyEntries(props.challengeName, setMyEntriesFromAPI, setMyEntries, setLoading, setScoresSorted); }; const mobileRender = () => { @@ -84,12 +84,16 @@ const MyEntries = (props) => { } break; default: - if (scoreSorted) { - newEntries = newEntries.sort((a, b) => a.evaluations[elem] - b.evaluations[elem]); - setScoreSorted(false); - } else { + let metricIndex = getPossibleMetrics().indexOf(elem); + let newScoresSorted = scoresSorted; + if (scoresSorted[metricIndex]) { newEntries = newEntries.sort((a, b) => b.evaluations[elem] - a.evaluations[elem]); - setScoreSorted(true); + newScoresSorted[metricIndex] = false; + setScoresSorted(newScoresSorted); + } else { + newEntries = newEntries.sort((a, b) => a.evaluations[elem] - b.evaluations[elem]); + newScoresSorted[metricIndex] = true; + setScoresSorted(newScoresSorted); } break; }