From 41fc6e4503d530f1d86030f3a8f8afe24e767d33 Mon Sep 17 00:00:00 2001 From: mattyl006 Date: Fri, 14 Oct 2022 11:35:48 +0200 Subject: [PATCH] my entries request work --- src/api/getMyEntries.js | 17 +++++++++++++++++ src/components/sections/MyEntries.js | 22 +++++++++++++++++++++- 2 files changed, 38 insertions(+), 1 deletion(-) create mode 100644 src/api/getMyEntries.js diff --git a/src/api/getMyEntries.js b/src/api/getMyEntries.js new file mode 100644 index 0000000..59c151d --- /dev/null +++ b/src/api/getMyEntries.js @@ -0,0 +1,17 @@ +import {API} from '../utils/globals'; +import KeyCloakService from '../services/KeyCloakService'; + +const getMyEntries = (challengeName, setDataState, setLoadingState) => { + fetch(`${API}/challenge-my-submissions/${challengeName}`, { + headers: {'Authorization': `Bearer ${KeyCloakService.getToken()}`} + }) + .then(response => response.json()) + .then(data => { + console.log(data); + setDataState(data); + if (setLoadingState) + setLoadingState(false); + }); +}; + +export default getMyEntries; \ No newline at end of file diff --git a/src/components/sections/MyEntries.js b/src/components/sections/MyEntries.js index 62a6112..7ade525 100644 --- a/src/components/sections/MyEntries.js +++ b/src/components/sections/MyEntries.js @@ -1,13 +1,33 @@ import React from 'react'; import {FlexColumn} from '../../utils/containers'; import {H2} from '../../utils/fonts'; +import getMyEntries from '../../api/getMyEntries'; + +const MyEntries = (props) => { + /* eslint-disable */ + const [myEntriesFromAPI, setMyEntriesFromAPI] = React.useState([]); + /* eslint-disable */ + const [myEntries, setMyEntries] = React.useState([]); + /* eslint-disable */ + const [loading, setLoading] = React.useState(true); + + React.useEffect(() => { + challengesRequest(); + }, []); + + const challengesRequest = () => { + getMyEntries(props.challengeName, setMyEntriesFromAPI); + getMyEntries(props.challengeName, setMyEntries, setLoading); + }; -const MyEntries = () => { return (

My entries

+ {/*{myEntries.map((entry, index) => {*/} + {/* */} + {/*})}*/}
); };