Skip to content

Commit

Permalink
Put category on top
Browse files Browse the repository at this point in the history
  • Loading branch information
ellatrix committed May 9, 2024
1 parent 41170d6 commit 5d9f316
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
isPatternFiltered,
allPatternsCategory,
myPatternsCategory,
starterContentCategory,
INSERTER_PATTERN_TYPES,
} from './utils';

Expand Down Expand Up @@ -67,6 +68,15 @@ export function usePatternCategories( rootClientId, sourceFilter = 'all' ) {
label: _x( 'Uncategorized' ),
} );
}

if (
patterns.find( ( pattern ) =>
pattern.categories.includes( 'core/content' )
)
) {
categories.unshift( starterContentCategory );
}

if (
filteredPatterns.some(
( pattern ) => pattern.type === INSERTER_PATTERN_TYPES.user
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ export const myPatternsCategory = {
label: __( 'My patterns' ),
};

export const starterContentCategory = {
name: 'core/content',
label: __( 'Starter content' ),
};

export function isPatternFiltered( pattern, sourceFilter, syncFilter ) {
const isUserPattern = pattern.name.startsWith( 'core/block' );
const isDirectoryPattern =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,7 @@ const usePatternsState = ( onInsert, rootClientId ) => {
);

const allCategories = useMemo( () => {
const categories = [
{
name: 'core/content',
label: __( 'Starter content' ),
},
...patternCategories,
];
const categories = [ ...patternCategories ];
userPatternCategories?.forEach( ( userCategory ) => {
if (
! categories.find(
Expand Down

0 comments on commit 5d9f316

Please sign in to comment.