Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(homepage-posts): post fetch for widget blocks #1066

Merged
merged 1 commit into from
Mar 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"dependencies": {
"@stripe/stripe-js": "^1.24.0",
"classnames": "^2.3.1",
"lodash": "^4.17.21",
"newspack-components": "^2.0.3",
"react": "^17.0.2",
"redux": "^4.1.2",
Expand Down
12 changes: 11 additions & 1 deletion src/blocks/homepage-articles/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,17 @@ const createFetchPostsSaga = blockNames => {

yield put( { type: 'DISABLE_UI' } );

const blockQueries = getBlockQueries( getBlocks(), blockNames );
// Ensure innerBlocks are populated for widget area blocks.
// See https://github.com/WordPress/gutenberg/issues/32607#issuecomment-890728216.
const blocks = getBlocks().map( block => {
const innerBlocks = select( 'core/block-editor' ).getBlocks( block.clientId );
return {
...block,
innerBlocks,
};
} );

const blockQueries = getBlockQueries( blocks, blockNames );

// Use requested specific posts ids as the starting state of exclusion list.
const specificPostsId = blockQueries.reduce( ( acc, { postsQuery } ) => {
Expand Down
3 changes: 2 additions & 1 deletion src/blocks/homepage-articles/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,8 @@ export const postsBlockSelector = ( select, { clientId, attributes } ) => {
const { getBlocks } = select( 'core/block-editor' );
const editorBlocksIds = getEditorBlocksIds( getEditorBlocks() );
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

getEditorBlocks() returns an empty array while in the widget editor, that's why another method for detecting the widget editor is used below.

// The block might be rendered in the block styles preview, not in the editor.
const isEditorBlock = editorBlocksIds.indexOf( clientId ) >= 0;
const isWidgetEditor = getBlocks().some( block => block.name === 'core/widget-area' );
const isEditorBlock = editorBlocksIds.indexOf( clientId ) >= 0 || isWidgetEditor;

const { getPosts, getError, isUIDisabled } = select( STORE_NAMESPACE );
const props = {
Expand Down