diff --git a/build/block.json b/build/block.json index 4db29d0..065cae1 100644 --- a/build/block.json +++ b/build/block.json @@ -6,7 +6,7 @@ "title": "Matchplay Results", "category": "widgets", "icon": "embed-generic", - "description": "Example block scaffolded with Create Block tool.", + "description": "Show results from a matchplay tournament.", "supports": { "html": false }, @@ -21,6 +21,9 @@ "selector": "div", "attribute": "data-tournament-id", "default": "" + }, + "data": { + "type": "object" } } } \ No newline at end of file diff --git a/build/index.asset.php b/build/index.asset.php index 3b6ba50..f9253ed 100644 --- a/build/index.asset.php +++ b/build/index.asset.php @@ -1 +1 @@ - array('wp-block-editor', 'wp-blocks', 'wp-components', 'wp-element', 'wp-i18n'), 'version' => 'aedcfaf64dcd52377178'); + array('wp-block-editor', 'wp-blocks', 'wp-components', 'wp-element', 'wp-i18n'), 'version' => '388c433128d11a09e6ca'); diff --git a/build/index.js b/build/index.js index 39a8553..d0759a9 100644 --- a/build/index.js +++ b/build/index.js @@ -1 +1 @@ -!function(){"use strict";var e,t={165:function(){var e=window.wp.blocks,t=window.wp.element,n=(window.wp.i18n,window.wp.blockEditor),r=window.wp.components;function l(){return l=Object.assign?Object.assign.bind():function(e){for(var t=1;ta({tournament_id:e})}))},save:function(e){let{attributes:r}=e;const a=n.useBlockProps.save();return(0,t.createElement)("div",l({},a,{"data-tournament-id":r.tournament_id}),(0,t.createElement)("table",null,(0,t.createElement)("thead",null,(0,t.createElement)("th",null,"Place"),(0,t.createElement)("th",null,"Player"),(0,t.createElement)("th",null,"Points")),(0,t.createElement)("tbody",null,(0,t.createElement)("tr",null,(0,t.createElement)("td",null,"1"),(0,t.createElement)("td",null,"Maddie"),(0,t.createElement)("td",null,"infinity")))))}})}},n={};function r(e){var l=n[e];if(void 0!==l)return l.exports;var a=n[e]={exports:{}};return t[e](a,a.exports,r),a.exports}r.m=t,e=[],r.O=function(t,n,l,a){if(!n){var o=1/0;for(s=0;s=a)&&Object.keys(r.O).every((function(e){return r.O[e](n[u])}))?n.splice(u--,1):(i=!1,a0&&e[s-1][2]>a;s--)e[s]=e[s-1];e[s]=[n,l,a]},r.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},function(){var e={826:0,431:0};r.O.j=function(t){return 0===e[t]};var t=function(t,n){var l,a,o=n[0],i=n[1],u=n[2],c=0;if(o.some((function(t){return 0!==e[t]}))){for(l in i)r.o(i,l)&&(r.m[l]=i[l]);if(u)var s=u(r)}for(t&&t(n);ca({tournament_id:e})}))),(0,t.createElement)("div",(0,n.useBlockProps)(),(0,t.createElement)("p",null,"Results for tournament id ",r.tournament_id),(0,t.createElement)("button",{onClick:()=>function(){let e=`https://matchplay.events/data/tournaments/${r.tournament_id}/standings`;fetch(e).then((e=>e.json())).then((e=>{let t={...e};a({data:t}),u(t),console.log(t)})).catch((e=>console.error(e)))}()},"Fetch Results"),o&&(0,t.createElement)(t.Fragment,null,(0,t.createElement)("table",{id:"tournament-results-table"},(0,t.createElement)("thead",null,(0,t.createElement)("tr",null,(0,t.createElement)("th",null,"Place"),(0,t.createElement)("th",null,"Player"),(0,t.createElement)("th",null,"Points"))),(0,t.createElement)("tbody",null,Object.keys(o).map(((e,n)=>(0,t.createElement)("tr",{key:e},(0,t.createElement)("td",null,o[n].position),(0,t.createElement)("td",null,o[n].name),(0,t.createElement)("td",null,o[n].points)))))))))},save:function(e){let{attributes:l}=e;const a=n.useBlockProps.save();return(0,t.createElement)("div",r({},a,{"data-tournament-id":l.tournament_id}),(0,t.createElement)("table",{id:"tournament-results-table"},(0,t.createElement)("thead",null,(0,t.createElement)("tr",null,(0,t.createElement)("th",null,"Place"),(0,t.createElement)("th",null,"Player"),(0,t.createElement)("th",null,"Points"))),(0,t.createElement)("tbody",null,Object.keys(l.data).map(((e,n)=>(0,t.createElement)("tr",{key:e},(0,t.createElement)("td",null,l.data[n].position),(0,t.createElement)("td",null,l.data[n].name),(0,t.createElement)("td",null,l.data[n].points)))))))}})}},n={};function l(e){var r=n[e];if(void 0!==r)return r.exports;var a=n[e]={exports:{}};return t[e](a,a.exports,l),a.exports}l.m=t,e=[],l.O=function(t,n,r,a){if(!n){var o=1/0;for(s=0;s=a)&&Object.keys(l.O).every((function(e){return l.O[e](n[c])}))?n.splice(c--,1):(u=!1,a0&&e[s-1][2]>a;s--)e[s]=e[s-1];e[s]=[n,r,a]},l.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},function(){var e={826:0,431:0};l.O.j=function(t){return 0===e[t]};var t=function(t,n){var r,a,o=n[0],u=n[1],c=n[2],i=0;if(o.some((function(t){return 0!==e[t]}))){for(r in u)l.o(u,r)&&(l.m[r]=u[r]);if(c)var s=c(l)}for(t&&t(n);i response.json()) + .then(response => { + let newData = { ...response }; + setAttributes( { data: newData } ); + setApiData(newData); + console.log(newData); + }) + .catch(err => console.error( err )); + } + return ( -
- setAttributes( { tournament_id: val } ) } - /> -
+ <> + + + setAttributes( { tournament_id: val } ) } + /> + + + +
+

Results for tournament id { attributes.tournament_id }

+ + {apiData && ( + <> + + + + + + + + + + {Object.keys(apiData).map((player, i) => { + return ( + + + + + + ); + })} + +
PlacePlayerPoints
{apiData[i].position}{apiData[i].name}{apiData[i].points}
+ + )} +
+ ); } diff --git a/src/save.js b/src/save.js index 034ebfe..a330c69 100644 --- a/src/save.js +++ b/src/save.js @@ -14,21 +14,29 @@ export default function save( { attributes } ) { const blockProps = useBlockProps.save(); return (
- - - - - - - + {attributes.data && ( +
PlacePlayerPoints
+ - - - + + + - -
1MaddieinfinityPlacePlayerPoints
- + + + {Object.keys(attributes.data).map((player, i) => { + return ( + + {attributes.data[i].position} + {attributes.data[i].name} + {attributes.data[i].points} + + ); + })} + + + )} + {/* Full Results on Matchplay */}