Skip to content

Commit

Permalink
Fix: pattern rendering issue (#66022)
Browse files Browse the repository at this point in the history
When navigating between the "All Patterns" tab (specifically on page 2) and the "Template Parts" tab, the patterns fail to load correctly, and a "No Results" message is displayed. This commit checks for a previous post type, and, if different, resets the pagination to page 1 to ensure the first page of new post types are shown.

---------

Co-authored-by: dhruvang21 <dhruvang21@git.wordpress.org>
Co-authored-by: ramonjd <ramonopoly@git.wordpress.org>
Co-authored-by: talldan <talldanwp@git.wordpress.org>
  • Loading branch information
4 people authored Oct 11, 2024
1 parent f083e29 commit e89e988
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions packages/edit-site/src/components/page-patterns/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ export default function DataviewsPatterns() {
const categoryId = categoryIdFromURL || PATTERN_DEFAULT_CATEGORY;
const [ view, setView ] = useState( DEFAULT_VIEW );
const previousCategoryId = usePrevious( categoryId );
const previousPostType = usePrevious( type );
const viewSyncStatus = view.filters?.find(
( { field } ) => field === 'sync-status'
)?.value;
Expand Down Expand Up @@ -121,10 +122,10 @@ export default function DataviewsPatterns() {

// Reset the page number when the category changes.
useEffect( () => {
if ( previousCategoryId !== categoryId ) {
if ( previousCategoryId !== categoryId || previousPostType !== type ) {
setView( ( prevView ) => ( { ...prevView, page: 1 } ) );
}
}, [ categoryId, previousCategoryId ] );
}, [ categoryId, previousCategoryId, previousPostType, type ] );
const { data, paginationInfo } = useMemo( () => {
// Search is managed server-side as well as filters for patterns.
// However, the author filter in template parts is done client-side.
Expand Down

0 comments on commit e89e988

Please sign in to comment.