Skip to content

Commit

Permalink
backport paging bug fixes (#53091)
Browse files Browse the repository at this point in the history
  • Loading branch information
glendaviesnz authored Jul 28, 2023
1 parent 513443b commit 02f3eb9
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
11 changes: 8 additions & 3 deletions packages/edit-site/src/components/page-patterns/grid.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
__experimentalText as Text,
Button,
} from '@wordpress/components';
import { useRef, useState, useMemo } from '@wordpress/element';
import { useRef, useMemo } from '@wordpress/element';
import { __, _x, _n, sprintf } from '@wordpress/i18n';
import { useAsyncList } from '@wordpress/compose';

Expand Down Expand Up @@ -82,8 +82,13 @@ function Pagination( { currentPage, numPages, changePage, totalItems } ) {
);
}

export default function Grid( { categoryId, items, ...props } ) {
const [ currentPage, setCurrentPage ] = useState( 1 );
export default function Grid( {
categoryId,
items,
currentPage,
setCurrentPage,
...props
} ) {
const gridRef = useRef();
const totalItems = items.length;
const pageIndex = currentPage - 1;
Expand Down
17 changes: 15 additions & 2 deletions packages/edit-site/src/components/page-patterns/patterns-list.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ const SYNC_DESCRIPTIONS = {
};

export default function PatternsList( { categoryId, type } ) {
const [ currentPage, setCurrentPage ] = useState( 1 );
const location = useLocation();
const history = useHistory();
const isMobileViewport = useViewportMatch( 'medium', '<' );
Expand All @@ -73,6 +74,16 @@ export default function PatternsList( { categoryId, type } ) {
}
);

const updateSearchFilter = ( value ) => {
setCurrentPage( 1 );
setFilterValue( value );
};

const updateSyncFilter = ( value ) => {
setCurrentPage( 1 );
setSyncFilter( value );
};

const id = useId();
const titleId = `${ id }-title`;
const descriptionId = `${ id }-description`;
Expand Down Expand Up @@ -109,7 +120,7 @@ export default function PatternsList( { categoryId, type } ) {
<FlexBlock className="edit-site-patterns__search-block">
<SearchControl
className="edit-site-patterns__search"
onChange={ ( value ) => setFilterValue( value ) }
onChange={ ( value ) => updateSearchFilter( value ) }
placeholder={ __( 'Search patterns' ) }
label={ __( 'Search patterns' ) }
value={ filterValue }
Expand All @@ -123,7 +134,7 @@ export default function PatternsList( { categoryId, type } ) {
label={ __( 'Filter by sync status' ) }
value={ syncFilter }
isBlock
onChange={ ( value ) => setSyncFilter( value ) }
onChange={ ( value ) => updateSyncFilter( value ) }
__nextHasNoMarginBottom
>
{ Object.entries( SYNC_FILTERS ).map(
Expand Down Expand Up @@ -157,6 +168,8 @@ export default function PatternsList( { categoryId, type } ) {
items={ patterns }
aria-labelledby={ titleId }
aria-describedby={ descriptionId }
currentPage={ currentPage }
setCurrentPage={ setCurrentPage }
/>
) }
{ ! isResolving && ! hasPatterns && <NoPatterns /> }
Expand Down

0 comments on commit 02f3eb9

Please sign in to comment.