Skip to content

Commit 2dd39d3

Browse files
authored
Merge pull request #531 from Automattic/master
Release 18/06/2020
2 parents d2e1ec6 + 84e0092 commit 2dd39d3

File tree

11 files changed

+372
-178
lines changed

11 files changed

+372
-178
lines changed

class-newspack-blocks.php

+4-18
Original file line numberDiff line numberDiff line change
@@ -362,18 +362,13 @@ function ( $acc, $block ) use ( $block_name ) {
362362
$args['orderby'] = 'post__in';
363363
} else {
364364
$args['posts_per_page'] = $posts_to_show;
365-
if ( ! self::is_experimental_mode() ) {
366-
$args['posts_per_page'] += count( $newspack_blocks_post_id );
367-
}
368365
if ( count( $newspack_blocks_all_specific_posts_ids ) ) {
369366
$args['post__not_in'] = $newspack_blocks_all_specific_posts_ids;
370367
}
371-
if ( self::is_experimental_mode() && count( $newspack_blocks_post_id ) ) {
372-
$args['post__not_in'] = array_merge(
373-
$args['post__not_in'] ?? [],
374-
array_keys( $newspack_blocks_post_id )
375-
);
376-
}
368+
$args['post__not_in'] = array_merge(
369+
$args['post__not_in'] ?? [],
370+
array_keys( $newspack_blocks_post_id )
371+
);
377372
if ( $authors && count( $authors ) ) {
378373
$args['author__in'] = $authors;
379374
}
@@ -504,14 +499,5 @@ public static function get_patterns_for_post_type( $post_type = null ) {
504499
}
505500
return $clean;
506501
}
507-
508-
/**
509-
* Is experimental mode flag set in wp-config.php
510-
*
511-
* @return boolean Experimental mode flag.
512-
*/
513-
public static function is_experimental_mode() {
514-
return defined( 'NEWSPACK_BLOCKS_EXPERIMENTAL_MODE' ) && NEWSPACK_BLOCKS_EXPERIMENTAL_MODE;
515-
}
516502
}
517503
Newspack_Blocks::init();

package-lock.json

+91
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+2
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@
6666
"lodash": "^4.17.15",
6767
"moment": "^2.24.0",
6868
"react": "^16.12.0",
69+
"redux": "^4.0.5",
70+
"redux-saga": "^1.1.3",
6971
"swiper": "4.5.1"
7072
},
7173
"scripts": {

src/blocks/donate/edit.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,7 @@ class Edit extends Component {
324324
label={ __( 'Error', 'newspack-blocks' ) }
325325
instructions={ error }
326326
>
327-
<ExternalLink href="/wp-admin/admin.php?page=newspack-donations-wizard#/">
327+
<ExternalLink href="/wp-admin/admin.php?page=newspack-reader-revenue-wizard#/donations">
328328
{ __( 'Go to donation settings to troubleshoot.', 'newspack-blocks' ) }
329329
</ExternalLink>
330330
</Placeholder>
@@ -340,7 +340,7 @@ class Edit extends Component {
340340
'newspack-blocks'
341341
) }
342342
>
343-
<ExternalLink href="/wp-admin/admin.php?page=newspack-donations-wizard#/">
343+
<ExternalLink href="/wp-admin/admin.php?page=newspack-reader-revenue-wizard#/donations">
344344
{ __( 'Set up donation settings.', 'newspack-blocks' ) }
345345
</ExternalLink>
346346
</Placeholder>
@@ -461,7 +461,7 @@ class Edit extends Component {
461461
) }
462462
</p>
463463

464-
<ExternalLink href="/wp-admin/admin.php?page=newspack-donations-wizard#/">
464+
<ExternalLink href="/wp-admin/admin.php?page=newspack-reader-revenue-wizard#/donations">
465465
{ __( 'Edit donation settings.', 'newspack-blocks' ) }
466466
</ExternalLink>
467467
</Fragment>

src/blocks/homepage-articles/edit.js

+59-24
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,12 @@
55
*/
66
import QueryControls from '../../components/query-controls';
77
import { STORE_NAMESPACE } from './store';
8-
import { isBlogPrivate, isSpecificPostModeActive, queryCriteriaFromAttributes } from './utils';
8+
import {
9+
getEditorBlocksIds,
10+
isBlogPrivate,
11+
shouldReflow,
12+
queryCriteriaFromAttributes,
13+
} from './utils';
914
import { formatAvatars, formatByline } from '../../shared/js/utils';
1015

1116
/**
@@ -91,7 +96,7 @@ const coverIcon = (
9196

9297
class Edit extends Component {
9398
renderPost = post => {
94-
const { attributes } = this.props;
99+
const { attributes, isUIDisabled } = this.props;
95100
const {
96101
showImage,
97102
imageShape,
@@ -121,7 +126,10 @@ class Edit extends Component {
121126
};
122127

123128
const postClasses = classNames(
124-
{ 'post-has-image': post.newspack_featured_image_src },
129+
{
130+
'post-has-image': post.newspack_featured_image_src,
131+
'homepage-posts-block__post--disabled': isUIDisabled,
132+
},
125133
post.newspack_article_classes
126134
);
127135

@@ -292,7 +300,6 @@ class Edit extends Component {
292300
setAttributes( { tagExclusions: _tagExclusions } )
293301
}
294302
/>
295-
296303
{ postLayout === 'grid' && (
297304
<RangeControl
298305
label={ __( 'Columns', 'newspack-blocks' ) }
@@ -467,6 +474,18 @@ class Edit extends Component {
467474
);
468475
};
469476

477+
componentDidMount() {
478+
this.props.triggerReflow();
479+
}
480+
componentDidUpdate( props ) {
481+
if ( shouldReflow( props, this.props ) ) {
482+
this.props.triggerReflow();
483+
}
484+
}
485+
componentWillUnmount() {
486+
this.props.triggerReflow();
487+
}
488+
470489
render() {
471490
/**
472491
* Constants
@@ -475,12 +494,11 @@ class Edit extends Component {
475494
const {
476495
attributes,
477496
className,
478-
clientId,
479497
setAttributes,
480498
isSelected,
481499
latestPosts,
482500
textColor,
483-
markPostsAsDisplayed,
501+
error,
484502
} = this.props;
485503

486504
const {
@@ -584,7 +602,6 @@ class Edit extends Component {
584602
},
585603
];
586604

587-
markPostsAsDisplayed( clientId, latestPosts );
588605
return (
589606
<Fragment>
590607
<div
@@ -606,9 +623,15 @@ class Edit extends Component {
606623
{ latestPosts && ! latestPosts.length && (
607624
<Placeholder>{ __( 'Sorry, no posts were found.', 'newspack-blocks' ) }</Placeholder>
608625
) }
609-
{ ! latestPosts && (
626+
{ ! latestPosts && ! error && (
610627
<Placeholder icon={ <Spinner /> } className="component-placeholder__align-center" />
611628
) }
629+
{ ! latestPosts && error && (
630+
<Placeholder className="component-placeholder__align-center homepage-posts-block--error">
631+
{ error }
632+
</Placeholder>
633+
) }
634+
612635
{ latestPosts && latestPosts.map( post => this.renderPost( post ) ) }
613636
</div>
614637
</div>
@@ -645,27 +668,39 @@ class Edit extends Component {
645668

646669
export default compose( [
647670
withColors( { textColor: 'color' } ),
648-
withSelect( ( select, props ) => {
649-
const { attributes, clientId } = props;
671+
withSelect( ( select, { clientId, attributes } ) => {
672+
const { getEditorBlocks, getBlocks } = select( 'core/editor' );
673+
const editorBlocksIds = getEditorBlocksIds( getEditorBlocks() );
674+
// The block might be rendered in the block styles preview, not in the editor.
675+
const isEditorBlock = editorBlocksIds.indexOf( clientId ) >= 0;
676+
677+
const { getPosts, getError, isUIDisabled } = select( STORE_NAMESPACE );
678+
679+
const props = {
680+
isEditorBlock,
681+
isUIDisabled: isUIDisabled(),
682+
error: getError( { clientId } ),
683+
topBlocksClientIdsInOrder: getBlocks().map( block => block.clientId ),
684+
};
650685

651-
const latestPostsQuery = queryCriteriaFromAttributes( attributes );
652-
if ( ! isSpecificPostModeActive( attributes ) ) {
653-
const postIdsToExclude = select( STORE_NAMESPACE ).previousPostIds( clientId );
654-
latestPostsQuery.exclude = postIdsToExclude.join( ',' );
686+
if ( isEditorBlock ) {
687+
props.latestPosts = getPosts( { clientId } );
688+
} else {
689+
// For block preview, display without deduplication. If there would be a way to match the outside-editor's
690+
// block clientId to the clientId of the block that's being previewed, the correct posts could be shown here.
691+
props.latestPosts = select( 'core' ).getEntityRecords(
692+
'postType',
693+
'post',
694+
queryCriteriaFromAttributes( attributes )
695+
);
655696
}
656697

657-
return {
658-
latestPosts: select( 'core' ).getEntityRecords( 'postType', 'post', latestPostsQuery ),
659-
};
698+
return props;
660699
} ),
661-
withDispatch( ( dispatch, props ) => {
662-
const { attributes } = props;
663-
const markPostsAsDisplayed = isSpecificPostModeActive( attributes )
664-
? dispatch( STORE_NAMESPACE ).markSpecificPostsAsDisplayed
665-
: dispatch( STORE_NAMESPACE ).markPostsAsDisplayed;
666-
700+
withDispatch( ( dispatch, { isEditorBlock } ) => {
667701
return {
668-
markPostsAsDisplayed,
702+
// Only editor blocks can trigger reflows.
703+
triggerReflow: isEditorBlock ? dispatch( STORE_NAMESPACE ).reflow : () => {},
669704
};
670705
} ),
671706
] )( Edit );

src/blocks/homepage-articles/editor.js

+5-3
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@
22
* Internal dependencies
33
*/
44
import { registerBlockType } from '@wordpress/blocks';
5-
import { name, settings } from '.';
5+
import { settings, name } from '.';
66
import { registerQueryStore } from './store';
77

8-
registerBlockType( `newspack-blocks/${ name }`, settings );
9-
registerQueryStore( `newspack-blocks/${ name }` );
8+
const BLOCK_NAME = `newspack-blocks/${ name }`;
9+
10+
registerBlockType( BLOCK_NAME, settings );
11+
registerQueryStore( BLOCK_NAME );

src/blocks/homepage-articles/editor.scss

+23
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
@import '../../shared/sass/variables';
22
@import '../../shared/sass/placeholder';
3+
@import '../../shared/sass/colors';
34

45
.type-scale-slider {
56
.dashicon {
@@ -48,3 +49,25 @@
4849
.editor-styles-wrapper.wpnbha__wp-block-button__wrapper {
4950
background-color: transparent;
5051
}
52+
53+
.homepage-posts-block {
54+
&--error.components-placeholder {
55+
color: $color__error;
56+
}
57+
&__post {
58+
&--disabled {
59+
position: relative;
60+
&::after {
61+
content: '';
62+
position: absolute;
63+
z-index: 2;
64+
width: 100%;
65+
height: 100%;
66+
top: 0;
67+
left: 0;
68+
background-color: #fff;
69+
opacity: 0.6;
70+
}
71+
}
72+
}
73+
}

0 commit comments

Comments
 (0)