my entries request work

This commit is contained in:
mattyl006 2022-10-14 11:35:48 +02:00
parent 9184847120
commit 41fc6e4503
2 changed files with 38 additions and 1 deletions

17
src/api/getMyEntries.js Normal file
View File

@ -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;

View File

@ -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 (
<FlexColumn padding='24px' as='section'>
<H2 as='h2'>
My entries
</H2>
{/*{myEntries.map((entry, index) => {*/}
{/* */}
{/*})}*/}
</FlexColumn>
);
};