Skip to content

Commit

Permalink
Remove wp_store from query block (#54359)
Browse files Browse the repository at this point in the history
* Remove wp_store from query block

* Add comment

* Remove unnecessary object cast

---------

Co-authored-by: Luis Herranz <luisherranz@gmail.com>
  • Loading branch information
SantosGuillamot and luisherranz committed Sep 12, 2023
1 parent bba4bbf commit 71f75e7
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 19 deletions.
26 changes: 11 additions & 15 deletions packages/block-library/src/query/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand All @@ -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.' ),
),
),
),
)
);
}
}

Expand Down
8 changes: 4 additions & 4 deletions packages/block-library/src/query/view.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand All @@ -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 );

Expand All @@ -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'
: '' );

Expand Down

0 comments on commit 71f75e7

Please sign in to comment.