correct endpoint for Leaderboard and entries column
This commit is contained in:
parent
294d9f1579
commit
28fd2cd854
13
src/api/getChallengeLeaderboard.js
Normal file
13
src/api/getChallengeLeaderboard.js
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
import {API} from '../utils/globals';
|
||||||
|
|
||||||
|
const getChallengeLeaderboard = (setDataState, setLoading, challengeName) => {
|
||||||
|
fetch(`${API}/leaderboard/${challengeName}`)
|
||||||
|
.then(response => response.json())
|
||||||
|
.then(data => {
|
||||||
|
setDataState(data);
|
||||||
|
if (setLoading)
|
||||||
|
setLoading(false);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
export default getChallengeLeaderboard;
|
@ -1,13 +0,0 @@
|
|||||||
import {API} from "../utils/globals";
|
|
||||||
|
|
||||||
const getChallengeSubmissions = (setDataState, setLoading, challengeName) => {
|
|
||||||
fetch(`${API}/challenge-all-submissions/${challengeName}`)
|
|
||||||
.then(response => response.json())
|
|
||||||
.then(data => {
|
|
||||||
setDataState(data);
|
|
||||||
if (setLoading)
|
|
||||||
setLoading(false);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
export default getChallengeSubmissions;
|
|
@ -57,7 +57,7 @@ const Pager = (props) => {
|
|||||||
backgroundColor={(props.pageNr === 1) ? 'transparent' : theme.colors.dark}/>
|
backgroundColor={(props.pageNr === 1) ? 'transparent' : theme.colors.dark}/>
|
||||||
<CircleNumber number={props.pageNr}/>
|
<CircleNumber number={props.pageNr}/>
|
||||||
<RightArrow as='button' src={polygon} onClick={props.nextPage} size='cover'
|
<RightArrow as='button' src={polygon} onClick={props.nextPage} size='cover'
|
||||||
backgroundColor={(props.pageNr === props.pages || props.pages === 0)
|
backgroundColor={(props.pageNr === props.pages)
|
||||||
? 'transparent' : theme.colors.dark}/>
|
? 'transparent' : theme.colors.dark}/>
|
||||||
</PagerStyle>
|
</PagerStyle>
|
||||||
);
|
);
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import {FlexColumn, FlexRow, Grid} from '../../../utils/containers';
|
import {FlexColumn, FlexRow, Grid} from '../../../utils/containers';
|
||||||
import getChallengeSubmissions from '../../../api/getChallengeSubmissions';
|
import getChallengeLeaderboard from '../../../api/getChallengeLeaderboard';
|
||||||
import {H3, Medium} from '../../../utils/fonts';
|
import {H3, Medium} from '../../../utils/fonts';
|
||||||
import _renderSubmissions from './_renderSubmissions';
|
import _renderSubmissions from './_renderSubmissions';
|
||||||
import Pager from '../Pager';
|
import Pager from '../Pager';
|
||||||
@ -12,7 +12,7 @@ import PropsTypes from 'prop-types';
|
|||||||
|
|
||||||
const Table = (props) => {
|
const Table = (props) => {
|
||||||
const headerElements = ['#', 'submitter', 'when', 'result', 'entries'];
|
const headerElements = ['#', 'submitter', 'when', 'result', 'entries'];
|
||||||
const [challengeData, setChallengeData] = React.useState({});
|
const [leaderboardData, setLeaderboardData] = React.useState({});
|
||||||
const [pageNr, setPageNr] = React.useState(1);
|
const [pageNr, setPageNr] = React.useState(1);
|
||||||
const [loading, setLoading] = React.useState(true);
|
const [loading, setLoading] = React.useState(true);
|
||||||
|
|
||||||
@ -21,16 +21,16 @@ const Table = (props) => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
const challengeDataRequest = () => {
|
const challengeDataRequest = () => {
|
||||||
getChallengeSubmissions(setChallengeData, setLoading, props.challengeName);
|
getChallengeLeaderboard(setLeaderboardData, setLoading, props.challengeName);
|
||||||
};
|
};
|
||||||
|
|
||||||
const renderSubmissions = () => {
|
const renderSubmissions = () => {
|
||||||
return _renderSubmissions(pageNr, challengeData.submissions
|
return _renderSubmissions(pageNr, leaderboardData.entries
|
||||||
? challengeData.submissions : []);
|
? leaderboardData.entries : []);
|
||||||
};
|
};
|
||||||
|
|
||||||
const nextPage = () => {
|
const nextPage = () => {
|
||||||
if (pageNr !== CALC_PAGES(challengeData.submissions ? challengeData.submissions : [])) {
|
if (pageNr !== CALC_PAGES(leaderboardData.entries ? leaderboardData.entries : [])) {
|
||||||
let newPage = pageNr + 1;
|
let newPage = pageNr + 1;
|
||||||
setPageNr(newPage);
|
setPageNr(newPage);
|
||||||
}
|
}
|
||||||
@ -86,13 +86,13 @@ const Table = (props) => {
|
|||||||
<>
|
<>
|
||||||
<Loading visible={loading}/>
|
<Loading visible={loading}/>
|
||||||
<Media query={theme.mobile}>
|
<Media query={theme.mobile}>
|
||||||
{mobileRender()}
|
{!loading ? mobileRender() : ''}
|
||||||
</Media>
|
</Media>
|
||||||
<Media query={theme.desktop}>
|
<Media query={theme.desktop}>
|
||||||
{desktopRender()}
|
{!loading ? desktopRender() : ''}
|
||||||
</Media>
|
</Media>
|
||||||
<Pager visible={!loading} pageNr={pageNr} nextPage={nextPage} previousPage={previousPage}
|
<Pager visible={!loading} pageNr={pageNr} nextPage={nextPage} previousPage={previousPage}
|
||||||
pages={CALC_PAGES(challengeData.submissions ? challengeData.submissions : [])}/>
|
pages={CALC_PAGES(leaderboardData.entries ? leaderboardData.entries : [])}/>
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
@ -17,7 +17,7 @@ const _renderSubmissions = (pageNr, submissions) => {
|
|||||||
if (submissions) {
|
if (submissions) {
|
||||||
return (
|
return (
|
||||||
<FlexColumn as='tbody' width='100%'>
|
<FlexColumn as='tbody' width='100%'>
|
||||||
{submissions.slice(n, n + ELEMENTS_PER_PAGE).map(({submitter, when, evaluations, version}, index) => {
|
{submissions.slice(n, n + ELEMENTS_PER_PAGE).map(({submitter, when, evaluations, times}, index) => {
|
||||||
return (
|
return (
|
||||||
<Grid as='tr' key={`leaderboard-row-${index}`} gridTemplateColumns='1fr 3fr 3fr 1fr 1fr'
|
<Grid as='tr' key={`leaderboard-row-${index}`} gridTemplateColumns='1fr 3fr 3fr 1fr 1fr'
|
||||||
gridGap='10px' margin='10px 0 0 0' position='relative' width='100%'>
|
gridGap='10px' margin='10px 0 0 0' position='relative' width='100%'>
|
||||||
@ -35,7 +35,7 @@ const _renderSubmissions = (pageNr, submissions) => {
|
|||||||
{evaluations[0] ? evaluations[0].score : 'xxx'}
|
{evaluations[0] ? evaluations[0].score : 'xxx'}
|
||||||
</Body>
|
</Body>
|
||||||
<Body as='td' textAlign='right' padding='0 2px 0 0'>
|
<Body as='td' textAlign='right' padding='0 2px 0 0'>
|
||||||
{version ? version.length : 1}
|
{times ? times : 1}
|
||||||
</Body>
|
</Body>
|
||||||
<Line as='td'/>
|
<Line as='td'/>
|
||||||
</Grid>
|
</Grid>
|
||||||
|
@ -46,6 +46,7 @@ const RENDER_ICO = (type) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const CALC_PAGES = (objects) => {
|
const CALC_PAGES = (objects) => {
|
||||||
|
if (objects.length === 0) return 1;
|
||||||
return Math.ceil(objects.length / ELEMENTS_PER_PAGE);
|
return Math.ceil(objects.length / ELEMENTS_PER_PAGE);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user