diff --git a/src/edit.js b/src/edit.js
index 3ce3f15..b41b490 100644
--- a/src/edit.js
+++ b/src/edit.js
@@ -1,6 +1,5 @@
-import { InspectorControls, useBlockProps } from '@wordpress/block-editor';
-import { TextControl, PanelBody } from '@wordpress/components';
-import { useState } from '@wordpress/element';
+import {InspectorControls, useBlockProps} from '@wordpress/block-editor';
+import {TextControl, PanelBody} from '@wordpress/components';
import './editor.scss';
/**
@@ -11,11 +10,7 @@ import './editor.scss';
*
* @return {WPElement} Element to render.
*/
-export default function Edit( { attributes, setAttributes } ) {
- const [standings, setStandings] = useState(null);
- const [players, setPlayers] = useState(null);
-
-
+export default function Edit({attributes, setAttributes}) {
function fetchTournamentData() {
const headers = {
"Authorization": `Bearer ${attributes.matchplay_api_key}`,
@@ -40,25 +35,25 @@ export default function Edit( { attributes, setAttributes } ) {
};
Object.keys(params).forEach(key => tournamentUrl.searchParams.append(key, params[key]));
+ // get players
fetch(tournamentUrl, {method: "GET", headers})
.then(response => response.json())
.then(response => {
- let players = { ...response };
- setAttributes( { players: players } );
- setPlayers(players);
- console.log(players);
+ let newData = {...response};
+ setAttributes({data: {players: newData}});
+ console.log(newData);
})
- .catch(err => console.error( err ));
+ .catch(err => console.error(err));
+ // get standings
fetch(standingsUrl, {method: "GET", headers})
.then(response => response.json())
.then(response => {
- let newData = { ...response };
- setAttributes( { standings: newData } );
- setStandings(newData);
+ let newData = {...response};
+ setAttributes({data: {standings: newData}});
console.log(newData);
})
- .catch(err => console.error( err ));
+ .catch(err => console.error(err));
}
return (
@@ -67,35 +62,35 @@ export default function Edit( { attributes, setAttributes } ) {
Results for tournament id { attributes.tournament_id }
+Results for tournament id {attributes.tournament_id}
- {attributes.players && attributes.standings && ( + {attributes.data.players && attributes.data.standings && ( <>Place | -Player | -Points | -
---|---|---|
Place | +Player | +Points | +
{attributes.standings[i].position} | -{attributes.players.find(p => p.player_id === attributes.standings[i].player_id).name} | -{attributes.standings[i].points} | -
{attributes.data.standings[i].position} | +{attributes.data.players.find(p => p.player_id === attributes.data.standings[i].player_id).name} | +{attributes.data.standings[i].points} | +