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 and ciampo committed Oct 14, 2024
1 parent dd21c3c commit 0d6a74b
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 0d6a74b

Please sign in to comment.