From 71f75e734ea6bcdb250220482890c54ae94d2753 Mon Sep 17 00:00:00 2001 From: Mario Santos <34552881+SantosGuillamot@users.noreply.github.com> Date: Tue, 12 Sep 2023 17:07:31 +0200 Subject: [PATCH] Remove `wp_store` from query block (#54359) * Remove wp_store from query block * Add comment * Remove unnecessary object cast --------- Co-authored-by: Luis Herranz --- packages/block-library/src/query/index.php | 26 +++++++++------------- packages/block-library/src/query/view.js | 8 +++---- 2 files changed, 15 insertions(+), 19 deletions(-) diff --git a/packages/block-library/src/query/index.php b/packages/block-library/src/query/index.php index f06073cc952000..4b8e8dee02a31a 100644 --- a/packages/block-library/src/query/index.php +++ b/packages/block-library/src/query/index.php @@ -23,9 +23,19 @@ function render_block_core_query( $attributes, $content, $block ) { // Add the necessary directives. $p->set_attribute( 'data-wp-interactive', true ); $p->set_attribute( 'data-wp-navigation-id', 'query-' . $attributes['queryId'] ); + // Use context to send translated strings. $p->set_attribute( 'data-wp-context', - wp_json_encode( array( 'core' => array( 'query' => (object) array() ) ) ) + wp_json_encode( + array( + 'core' => array( + 'query' => array( + 'loadingText' => __( 'Loading page, please wait.' ), + 'loadedText' => __( 'Page Loaded.' ), + ), + ), + ) + ) ); $content = $p->get_updated_html(); @@ -49,20 +59,6 @@ class="wp-block-query__enhanced-pagination-animation" $last_div_position, 0 ); - - // Use state to send translated strings. - wp_store( - array( - 'state' => array( - 'core' => array( - 'query' => array( - 'loadingText' => __( 'Loading page, please wait.' ), - 'loadedText' => __( 'Page Loaded.' ), - ), - ), - ), - ) - ); } } diff --git a/packages/block-library/src/query/view.js b/packages/block-library/src/query/view.js index cbd5573e05c6f9..78cc423c80661a 100644 --- a/packages/block-library/src/query/view.js +++ b/packages/block-library/src/query/view.js @@ -32,7 +32,7 @@ store( { actions: { core: { query: { - navigate: async ( { event, ref, context, state } ) => { + navigate: async ( { event, ref, context } ) => { if ( isValidLink( ref ) && isValidEvent( event ) ) { event.preventDefault(); @@ -42,7 +42,7 @@ store( { // Don't announce the navigation immediately, wait 300 ms. const timeout = setTimeout( () => { context.core.query.message = - state.core.query.loadingText; + context.core.query.loadingText; context.core.query.animation = 'start'; }, 300 ); @@ -55,9 +55,9 @@ store( { // same, we use a no-break space similar to the @wordpress/a11y // package: https://github.com/WordPress/gutenberg/blob/c395242b8e6ee20f8b06c199e4fc2920d7018af1/packages/a11y/src/filter-message.js#L20-L26 context.core.query.message = - state.core.query.loadedText + + context.core.query.loadedText + ( context.core.query.message === - state.core.query.loadedText + context.core.query.loadedText ? '\u00A0' : '' );