Skip to content
This repository has been archived by the owner on Feb 23, 2024. It is now read-only.

Commit

Permalink
fix logic
Browse files Browse the repository at this point in the history
  • Loading branch information
gigitux committed May 16, 2023
1 parent 670893e commit 4a41c32
Showing 1 changed file with 19 additions and 17 deletions.
36 changes: 19 additions & 17 deletions assets/js/blocks/product-query/variations/product-query.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,20 +65,16 @@ const registerProductsBlock = ( attributes: QueryBlockAttributes ) => {
};

if ( isWpVersion( '6.1', '>=' ) ) {
const store = select( 'core/edit-site' );

if ( isSiteEditorPage( store ) ) {
let currentTemplateId: string | undefined;

subscribe( () => {
const previousTemplateId = currentTemplateId;

currentTemplateId = store?.getEditedPostId();

if ( previousTemplateId === currentTemplateId ) {
return;
}
let currentTemplateId: string | undefined;
subscribe( () => {
const previousTemplateId = currentTemplateId;
const store = select( 'core/edit-site' );
currentTemplateId = store?.getEditedPostId();
if ( previousTemplateId === currentTemplateId ) {
return;
}

if ( isSiteEditorPage( store ) ) {
const queryAttributes = {
...QUERY_DEFAULT_ATTRIBUTES,
query: {
Expand All @@ -91,8 +87,14 @@ if ( isWpVersion( '6.1', '>=' ) ) {
unregisterBlockVariation( QUERY_LOOP_ID, VARIATION_NAME );

registerProductsBlock( queryAttributes );
} );
} else {
registerProductsBlock( QUERY_DEFAULT_ATTRIBUTES );
}
}
}, 'core/edit-site' );

let isBlockRegistered = false;
subscribe( () => {
if ( ! isBlockRegistered ) {
isBlockRegistered = true;
registerProductsBlock( QUERY_DEFAULT_ATTRIBUTES );
}
}, 'core/edit-post' );
}

0 comments on commit 4a41c32

Please sign in to comment.