Skip to content

Commit

Permalink
Implement BlockDescription function #55
Browse files Browse the repository at this point in the history
  • Loading branch information
bobbingwide committed Sep 18, 2022
1 parent 58baa82 commit 7c73b89
Showing 1 changed file with 36 additions and 2 deletions.
38 changes: 36 additions & 2 deletions src/oik-blocklist/blocklist.js
Expand Up @@ -154,7 +154,8 @@ function BlockListItem( block, showBlockLink ) {
blockSupportsInserter = BlockSupportsInserter( block) ;
var blockDescription = null;
//console.log( block.description );
blockDescription = ( typeof block.description === 'string' ) ? block.description : 'TBC';
blockDescription = BlockDescription( block.description );
// ( typeof block.description === 'string' ) ? block.description : <span>{block.description}</span>;
//blockDescription = <Fragment>{block.description}</Fragment>;

//console.log( block.block_name + '|' + block.name );
Expand Down Expand Up @@ -205,8 +206,9 @@ function BlockListItem( block, showBlockLink ) {
*/
function BlockCreateBlockLink( block, component ) {
var url = ajaxurl;
var blockDescription = ( typeof block.description === 'string') ? block.description : 'TBC';
//var blockDescription = ( typeof block.description === 'string') ? block.description : 'TBC';
//var blockDescription = renderToString( <Fragment>{block.description}</Fragment> );
var blockDescription = BlockDescription( block.description );
var keywords = block.keywords ? block.keywords.join() : null;
url = addQueryArgs( url, { action: 'oiksc_create_or_update_block' });
url = addQueryArgs( url, { title: block.title });
Expand All @@ -216,6 +218,8 @@ function BlockCreateBlockLink( block, component ) {
url = addQueryArgs( url, { keywords: keywords});
url = addQueryArgs( url, { category: block.category});
url = addQueryArgs( url, { variation: block.block_name});
// This doesn't seem to work anymore!
console.log( block.icon );
var blockIcon = renderToString( <BlockIcon icon={block.icon } /> );
url = addQueryArgs( url, { icon: blockIcon });
//console.log( url );
Expand Down Expand Up @@ -243,4 +247,34 @@ function BlockNoLink( block, component ) {
);
}

/**
* Returns a string for the block description.
*
* The renderToString() function doesn't work during save().
* This function is a hacky workaround for those blocks that
* don't simply provide a string.
* We assume we can use the content of the first block
* since it's expected to be a paragraph.
*
* @param description
* @returns {string}
* @constructor
*/

function BlockDescription( description ) {

if ( typeof description === 'string' ) {
return(description);
} else {
//console.log( description);
var descFromFirstPara = 'TBC';
var children = description.props.children;
if ( children[0].type === 'p' ) {
descFromFirstPara = children[0].props.children;
}
return( descFromFirstPara );
}

}

export { BlockListStyled, BlockListItem };

0 comments on commit 7c73b89

Please sign in to comment.