From 3ff0c6ea8715cf6c565edc32fbf66f04186c895a Mon Sep 17 00:00:00 2001 From: Mateusz Tylka Date: Fri, 10 Mar 2023 14:20:41 +0100 Subject: [PATCH] correct redirect back from submission, submission loading and env in submission api request --- .env | 2 +- src/api/challengeSubmissionPost.js | 56 +++++---- .../specific_challenge/Challenge.js | 66 +++++------ .../DesktopChallengeMenu.js | 2 +- src/components/specific_challenge/Submit.js | 111 ++++++++++++------ 5 files changed, 138 insertions(+), 99 deletions(-) diff --git a/.env b/.env index 0c0a154..9a7fd9a 100644 --- a/.env +++ b/.env @@ -2,4 +2,4 @@ REACT_APP_KC_URL=https://auth-dev.csi.wmi.amu.edu.pl/ REACT_APP_KC_REALM=gonito-dev REACT_APP_KC_CLIENT_ID=gonito-dev-localhost -REACT_APP_API=https://gonito.net/api +REACT_APP_API=https://gonito-back-dev.csi.wmi.amu.edu.pl/api \ No newline at end of file diff --git a/src/api/challengeSubmissionPost.js b/src/api/challengeSubmissionPost.js index 517e55e..4e8f1c8 100644 --- a/src/api/challengeSubmissionPost.js +++ b/src/api/challengeSubmissionPost.js @@ -1,30 +1,38 @@ import KeyCloakService from '../services/KeyCloakService'; -import {API} from '../utils/globals'; +import { API } from '../utils/globals'; -const challengeSubmission = (challengeName, repoUrl, repoBranch, description, setLoading) => { - const details = { - 'f1': description, - 'f3': repoUrl, - 'f4': repoBranch - }; - let formBody = []; - for (let property in details) { - let encodedKey = encodeURIComponent(property); - let encodedValue = encodeURIComponent(details[property]); - formBody.push(encodedKey + '=' + encodedValue); - } - formBody = formBody.join('&'); - fetch(`${API}/challenge-submission/${challengeName}`, { - method: 'POST', - headers: { - 'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8', - 'Authorization': `Bearer ${KeyCloakService.getToken()}` - }, - body: formBody - }).then((resp) => resp.json()) +const challengeSubmission = ( + challengeName, + repoUrl, + repoBranch, + description, + setLoading +) => { + const details = { + f1: description, + f3: repoUrl, + f4: repoBranch, + }; + let formBody = []; + for (let property in details) { + let encodedKey = encodeURIComponent(property); + let encodedValue = encodeURIComponent(details[property]); + formBody.push(encodedKey + '=' + encodedValue); + } + formBody = formBody.join('&'); + fetch(`${API}/challenge-submission/${challengeName}`, { + method: 'POST', + headers: { + 'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8', + Authorization: `Bearer ${KeyCloakService.getToken()}`, + }, + body: formBody, + }) + .then((resp) => resp.json()) .then((data) => { - setLoading(true); - window.location.replace(`https://gonito.net/open-view-progress/${data}#form`); + setLoading(true); + const processUrl = API.replace('/api', ''); + window.location.replace(`${processUrl}/open-view-progress/${data}#form`); }); }; diff --git a/src/components/specific_challenge/Challenge.js b/src/components/specific_challenge/Challenge.js index 9211935..d4810de 100644 --- a/src/components/specific_challenge/Challenge.js +++ b/src/components/specific_challenge/Challenge.js @@ -1,7 +1,7 @@ import React from 'react'; import { Container, FlexColumn, FlexRow, Svg } from '../../utils/containers'; import { useParams } from 'react-router-dom'; -import { H1, H2, Medium } from '../../utils/fonts'; +import { H1, Medium } from '../../utils/fonts'; import theme from '../../utils/theme'; import MobileChallengeMenu from './MobileChallengeMenu'; import Leaderboard from './Leaderboard/Leaderboard'; @@ -70,29 +70,33 @@ const Challenge = (props) => { }; const mobileRender = () => { - return ( - - -

- {challenge.title} -

- - - {sectionRender()} -
- ); + if (!loading) { + return ( + + +

+ {challenge.title} +

+ + + {sectionRender()} +
+ ); + } else { + return ; + } }; const desktopRender = () => { @@ -131,19 +135,7 @@ const Challenge = (props) => { ); } else { - return ( - -

Submission processing...

- -
- ); + return ; } }; diff --git a/src/components/specific_challenge/DesktopChallengeMenu.js b/src/components/specific_challenge/DesktopChallengeMenu.js index 6986ae1..c3ce87b 100644 --- a/src/components/specific_challenge/DesktopChallengeMenu.js +++ b/src/components/specific_challenge/DesktopChallengeMenu.js @@ -48,7 +48,7 @@ const DesktopChallengeMenu = (props) => {