From 09b1e6751321d831f838af56a2bca4b5ecc65a7b Mon Sep 17 00:00:00 2001
From: mattyl006
Date: Tue, 26 Jul 2022 11:52:38 +0200
Subject: [PATCH] correct api response for particular challenge data
---
src/api/getChallengeInfo.js | 11 +++++++++
.../elements/Table/_renderSubmissions.js | 2 +-
src/pages/Challenge.js | 24 ++++++-------------
3 files changed, 19 insertions(+), 18 deletions(-)
create mode 100644 src/api/getChallengeInfo.js
diff --git a/src/api/getChallengeInfo.js b/src/api/getChallengeInfo.js
new file mode 100644
index 0000000..be39e74
--- /dev/null
+++ b/src/api/getChallengeInfo.js
@@ -0,0 +1,11 @@
+import {API} from "../utils/globals";
+
+const getChallengeInfo = (setState, challengeName) => {
+ fetch(`${API}/challenge-info/${challengeName}`)
+ .then(response => response.json())
+ .then(data => {
+ setState(data);
+ });
+}
+
+export default getChallengeInfo;
\ No newline at end of file
diff --git a/src/components/elements/Table/_renderSubmissions.js b/src/components/elements/Table/_renderSubmissions.js
index 8569958..adfb0a1 100644
--- a/src/components/elements/Table/_renderSubmissions.js
+++ b/src/components/elements/Table/_renderSubmissions.js
@@ -25,7 +25,7 @@ const _renderSubmissions = (pageNr, submissions) => {
{index + n + 1}
- {submission.submitter ? submission.submitter : '[anonymized]'}
+ {submission.submitter ? submission.submitter : '[anonymous]'}
{submission.when ? `${submission.when.slice(11, 16)} ${submission.when.slice(0, 10)}`
diff --git a/src/pages/Challenge.js b/src/pages/Challenge.js
index a8daff1..6627807 100644
--- a/src/pages/Challenge.js
+++ b/src/pages/Challenge.js
@@ -2,7 +2,6 @@ import React from "react";
import {Container, FlexColumn, FlexRow, Svg} from "../utils/containers";
import {useParams} from "react-router-dom";
import {H1, Medium} from "../utils/fonts";
-import getChallenges from "../api/getChallenges";
import theme from "../utils/theme";
import MobileChallengeMenu from "../components/elements/MobileChallengeMenu";
import Leaderboard from "../components/sections/Leaderboard";
@@ -14,26 +13,17 @@ import Media from "react-media";
import DesktopChallengeMenu from "../components/elements/DesktopChallengeMenu";
import {MINI_DESCRIPTION_RENDER, RENDER_ICO} from "../utils/globals";
import textIco from "../assets/text_ico.svg";
+import getChallengeInfo from "../api/getChallengeInfo";
const Challenge = () => {
const challengeName = useParams().challengeId;
- const [challenges, setChallenges] = React.useState([]);
+ const [challenge, setChallenge] = React.useState([]);
const [section, setSection] = React.useState(0);
React.useEffect(() => {
- getChallenges(setChallenges);
+ getChallengeInfo(setChallenge, challengeName);
}, []);
- const getChallenge = () => {
- if (challenges.length !== 0) {
- for (let challenge of challenges) {
- if (challenge.name === challengeName)
- return challenge
- }
- }
- return '';
- }
-
const sectionRender = () => {
switch (section) {
case 0:
@@ -55,7 +45,7 @@ const Challenge = () => {
return (
- {getChallenge().title}
+ {challenge.title}
@@ -72,13 +62,13 @@ const Challenge = () => {
- {getChallenge().title}
+ {challenge.title}
- {MINI_DESCRIPTION_RENDER(getChallenge().description)}
+ {MINI_DESCRIPTION_RENDER(challenge.description)}
-