Skip to content

Commit 104b2f7

Browse files
authored
Merge pull request #118 from ryanwelcher/fix/pagination
Resurrect the pagination toggle control.
2 parents 0ce3621 + a265254 commit 104b2f7

File tree

1 file changed

+23
-32
lines changed

1 file changed

+23
-32
lines changed

src/components/pagination-toggle.js

Lines changed: 23 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,30 @@
11
/**
22
* WordPress dependencies
33
*/
4-
import { useSelect } from '@wordpress/data';
5-
import { store as blockEditorStore } from '@wordpress/block-editor';
6-
import { useEffect } from '@wordpress/element';
4+
import { ToggleControl } from '@wordpress/components';
5+
import { __ } from '@wordpress/i18n';
76

8-
/**
9-
* Check for the core/query-pagination block.
10-
*
11-
* @param {Array} blocks The array of innerBlocks
12-
* @return {string|boolean} Return either the clientId or false if not found.
13-
*/
14-
const getPaginationBlockClientId = ( blocks ) => {
15-
return blocks.find( ( block ) => block.name === 'core/query-pagination' )
16-
?.clientId;
17-
};
7+
export const PaginationToggle = ( { attributes, setAttributes } ) => {
8+
const { query: { disable_pagination: disablePagination } = {} } =
9+
attributes;
1810

19-
export const PaginationToggle = ( { attributes, setAttributes, clientId } ) => {
20-
const innerBlocks = useSelect(
21-
( select ) =>
22-
select( blockEditorStore ).getBlocksByClientId( clientId )[ 0 ]
23-
?.innerBlocks
11+
return (
12+
<ToggleControl
13+
label={ __( 'Disable pagination', 'advanced-query-loop' ) }
14+
help={ __(
15+
'Disabling pagination will not show any pagination controls on the front end. It can also provide a performance improvement for complicated queries.',
16+
'advanced-query-loop'
17+
) }
18+
checked={ !! disablePagination }
19+
onChange={ () => {
20+
setAttributes( {
21+
query: {
22+
...attributes.query,
23+
disable_pagination: ! disablePagination,
24+
},
25+
} );
26+
} }
27+
__nextHasNoMarginBottom
28+
/>
2429
);
25-
26-
useEffect( () => {
27-
setAttributes( {
28-
query: {
29-
...attributes.query,
30-
disable_pagination: ! getPaginationBlockClientId( innerBlocks )
31-
? true
32-
: false,
33-
},
34-
} );
35-
}, [ innerBlocks, setAttributes ] );
36-
37-
// There is no UI for component.
38-
return null;
3930
};

0 commit comments

Comments
 (0)