wp-matchplay/src/save.js

46 lines
1.4 KiB
JavaScript
Raw Normal View History

2023-04-19 21:14:01 +00:00
import { useBlockProps } from '@wordpress/block-editor';
import { ExternalLink } from '@wordpress/components';
/**
* The save function defines the way in which the different attributes should
* be combined into the final markup, which is then serialized by the block
* editor into `post_content`.
*
* @see https://developer.wordpress.org/block-editor/reference-guides/block-api/block-edit-save/#save
*
* @return {WPElement} Element to render.
*/
export default function save( { attributes } ) {
const blockProps = useBlockProps.save();
return (
<div { ...blockProps } data-tournament-id={ attributes.tournament_id }>
2023-07-19 20:46:52 +00:00
{attributes.data?.players && attributes.data?.standings && (
2023-04-20 15:53:40 +00:00
<table id="tournament-results-table">
<thead>
2023-04-19 21:14:01 +00:00
<tr>
2023-04-20 15:53:40 +00:00
<th>Place</th>
<th>Player</th>
<th>Points</th>
2023-04-19 21:14:01 +00:00
</tr>
2023-04-20 15:53:40 +00:00
</thead>
<tbody>
2023-07-19 20:44:31 +00:00
{Object.keys(attributes.data.standings).map((player, i) => {
2023-04-20 15:53:40 +00:00
return (
<tr key={player}>
2023-07-19 20:44:31 +00:00
<td>{attributes.data.standings[i].position}</td>
2023-07-19 20:49:49 +00:00
<td>{attributes.data.players.find(p => p.playerId === attributes.data.standings[i].playerId).name}</td>
2023-07-19 20:44:31 +00:00
<td>{attributes.data.standings[i].points}</td>
2023-04-20 15:53:40 +00:00
</tr>
);
})}
</tbody>
</table>
)}
2023-04-19 21:14:01 +00:00
{/* <ExternalLink href={ `https://next.matchplay.events/tournaments/${ attributes.tournament_id }/standings` }>
Full Results on Matchplay
</ExternalLink> */}
</div>
);
}