Skip to content

Commit

Permalink
feat: hide navigation if only one post presented
Browse files Browse the repository at this point in the history
  • Loading branch information
adekbadek committed Apr 6, 2021
1 parent 9660922 commit c439d60
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/blocks/carousel/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ class Edit extends Component {
);
const dateFormat = __experimentalGetSettings().formats.date;
const hasNoPosts = latestPosts && ! latestPosts.length;
const hasOnePost = latestPosts && latestPosts.length === 1;
return (
<Fragment>
<div className={ classes } ref={ this.carouselRef }>
Expand Down Expand Up @@ -212,7 +213,7 @@ class Edit extends Component {
</article>
) ) }
</div>
{ ! hasNoPosts && (
{ ! hasNoPosts && ! hasOnePost && (
<>
<button
className="amp-carousel-button amp-carousel-button-prev swiper-button-prev"
Expand Down
5 changes: 4 additions & 1 deletion src/blocks/carousel/view.php
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ function newspack_blocks_render_block_carousel( $attributes ) {
'<div class="swiper-pagination-bullets amp-pagination">%s</div>',
implode( '', $buttons )
);
$navigation = sprintf(
$navigation = 1 === $counter ? '' : sprintf(
'<button class="swiper-button swiper-button-prev" aria-label="%s"></button><button class="swiper-button swiper-button-next" aria-label="%s"></button>',
esc_attr__( 'Previous Slide', 'newspack-blocks' ),
esc_attr__( 'Next Slide', 'newspack-blocks' )
Expand All @@ -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(
'<div class="%1$s" id="wp-block-newspack-carousel__%2$d" %3$s>%4$s%5$s%6$s</div>',
esc_attr( $classes ),
Expand Down

0 comments on commit c439d60

Please sign in to comment.