From ccecb00423220e002c57e0e3df0d49584fb85883 Mon Sep 17 00:00:00 2001 From: Adam Borowski Date: Fri, 2 Apr 2021 18:09:00 +0200 Subject: [PATCH 1/4] feat(carousel): align no posts found message --- src/blocks/carousel/edit.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/blocks/carousel/edit.js b/src/blocks/carousel/edit.js index 45602fd10..53d75383e 100644 --- a/src/blocks/carousel/edit.js +++ b/src/blocks/carousel/edit.js @@ -122,11 +122,14 @@ class Edit extends Component { autoplay && 'wp-block-newspack-blocks-carousel__autoplay-playing' ); const dateFormat = __experimentalGetSettings().formats.date; + const hasNoPosts = latestPosts && ! latestPosts.length; return (
- { latestPosts && ! latestPosts.length && ( - { __( 'Sorry, no posts were found.' ) } + { hasNoPosts && ( + +
{ __( 'Sorry, no posts were found.' ) }
+
) } { ! latestPosts && ( } className="component-placeholder__align-center" /> From 1aba5b55bef99e80678e99af5c1add1b9a50e1cf Mon Sep 17 00:00:00 2001 From: Adam Borowski Date: Fri, 2 Apr 2021 18:22:17 +0200 Subject: [PATCH 2/4] feat: handle posts with no featured image Closes #443 --- includes/class-newspack-blocks-api.php | 15 --- src/blocks/carousel/edit.js | 128 ++++++++++++------------- src/blocks/carousel/view.php | 29 +++--- src/blocks/carousel/view.scss | 5 + 4 files changed, 82 insertions(+), 95 deletions(-) diff --git a/includes/class-newspack-blocks-api.php b/includes/class-newspack-blocks-api.php index 7bd2add71..869a7e70e 100644 --- a/includes/class-newspack-blocks-api.php +++ b/includes/class-newspack-blocks-api.php @@ -559,21 +559,6 @@ public static function add_post_title_wildcard_search( $where, $query ) { * @return array $args Filtered request parameters. */ public static function post_meta_request_params( $args, $request ) { - $params = $request->get_params(); - - if ( - isset( $params['meta_key'], $params['meta_value_num'], $params['meta_compare'] ) && - '_thumbnail_id' === $params['meta_key'] && - '0' === $params['meta_value_num'] && - '>' === $params['meta_compare'] - ) { - // phpcs:disable WordPress.DB.SlowDBQuery - $args['meta_key'] = $params['meta_key']; - $args['meta_value_num'] = $params['meta_value_num']; - $args['meta_compare'] = $params['meta_compare']; - // phpcs:enable WordPress.DB.SlowDBQuery - } - if ( $request->get_param( 'suppress_password_protected_posts' ) ) { $args['has_password'] = false; } diff --git a/src/blocks/carousel/edit.js b/src/blocks/carousel/edit.js index 53d75383e..73bed7bc7 100644 --- a/src/blocks/carousel/edit.js +++ b/src/blocks/carousel/edit.js @@ -149,70 +149,71 @@ class Edit extends Component { ) }
- { latestPosts.map( - post => - post.newspack_featured_image_src && ( -
-
- { post.newspack_featured_image_src && ( - - - - ) } -
-
- { post.newspack_post_sponsors && ( - - - { post.newspack_post_sponsors[ 0 ].flag } - - - ) } - { showCategory && - post.newspack_category_info.length && - ! post.newspack_post_sponsors && ( - - ) } -

- { decodeEntities( post.title.rendered.trim() ) } -

-
- { post.newspack_post_sponsors && - formatSponsorLogos( post.newspack_post_sponsors ) } - { post.newspack_post_sponsors && - formatSponsorByline( post.newspack_post_sponsors ) } - { showAuthor && - showAvatar && - ! post.newspack_post_sponsors && - formatAvatars( post.newspack_author_info ) } - { showAuthor && - ! post.newspack_post_sponsors && - formatByline( post.newspack_author_info ) } - { showDate && ( - - ) } + { latestPosts.map( post => ( + - ) - ) } + ) } +

+ { decodeEntities( post.title.rendered.trim() ) } +

+
+ { post.newspack_post_sponsors && + formatSponsorLogos( post.newspack_post_sponsors ) } + { post.newspack_post_sponsors && + formatSponsorByline( post.newspack_post_sponsors ) } + { showAuthor && + showAvatar && + ! post.newspack_post_sponsors && + formatAvatars( post.newspack_author_info ) } + { showAuthor && + ! post.newspack_post_sponsors && + formatByline( post.newspack_author_info ) } + { showDate && ( + + ) } +
+
+
+ ) ) }
-
- { ! hasNoPosts && ( + { ! hasNoPosts && ! hasOnePost && ( <> ', esc_attr__( 'Previous Slide', 'newspack-blocks' ), esc_attr__( 'Next Slide', 'newspack-blocks' ) @@ -257,6 +257,9 @@ function newspack_blocks_render_block_carousel( $attributes ) { $data_attributes[] = sprintf( 'data-autoplay_delay=%s', esc_attr( $delay ) ); } Newspack_Blocks::enqueue_view_assets( 'carousel' ); + if ( 1 === $counter ) { + $selector = ''; + } return sprintf( '', esc_attr( $classes ),