);
}
function RelatedPostsPreviewRows( props ) {
const className = 'jp-related-posts-i2__row';
let topRowEnd = 0;
const displayLowerRow = props.posts.length > 3;
switch ( props.posts.length ) {
case 2:
case 4:
case 5:
topRowEnd = 2;
break;
default:
topRowEnd = 3;
break;
}
return (
{ props.posts.slice( 0, topRowEnd ) }
{ displayLowerRow && (
{ props.posts.slice( topRowEnd ) }
) }
);
}
class RelatedPostsEdit extends Component {
render() {
const { attributes, className, posts, setAttributes, instanceId } = this.props;
const { displayContext, displayDate, displayThumbnails, postLayout, postsToShow } = attributes;
const layoutControls = [
{
icon: 'grid-view',
title: __( 'Grid View', 'jetpack' ),
onClick: () => setAttributes( { postLayout: 'grid' } ),
isActive: postLayout === 'grid',
},
{
icon: 'list-view',
title: __( 'List View', 'jetpack' ),
onClick: () => setAttributes( { postLayout: 'list' } ),
isActive: postLayout === 'list',
},
];
// To prevent the block from crashing, we need to limit ourselves to the
// posts returned by the backend - so if we want 6 posts, but only 3 are
// returned, we need to limit ourselves to those 3 and fill in the rest
// with placeholders.
//
// Also, if the site does not have sufficient posts to display related ones
// (minimum 10 posts), we also use this code block to fill in the
// placeholders.
const previewClassName = 'jp-relatedposts-i2';
const displayPosts = [];
for ( let i = 0; i < postsToShow; i++ ) {
if ( posts[ i ] ) {
displayPosts.push(
);
} else {
displayPosts.push(
);
}
}
return (
setAttributes( { displayThumbnails: value } ) }
/>
setAttributes( { displayDate: value } ) }
/>
setAttributes( { displayContext: value } ) }
/>
setAttributes( { postsToShow: Math.min( value, MAX_POSTS_TO_SHOW ) } )
}
min={ 1 }
max={ MAX_POSTS_TO_SHOW }
/>