Skip to content

Commit

Permalink
Revert usePatternsState to return an array instead of an object (#54582)
Browse files Browse the repository at this point in the history
  • Loading branch information
glendaviesnz authored Sep 19, 2023
1 parent a2e4ac3 commit 23bb930
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ function PatternList( {
const [ destinationRootClientId, onInsertBlocks ] = useInsertionPoint( {
shouldFocusBlock: true,
} );
const { patterns: allPatterns, onClickPattern } = usePatternsState(
const [ patterns, , onClickPattern ] = usePatternsState(
onInsertBlocks,
destinationRootClientId
);
Expand All @@ -88,7 +88,7 @@ function PatternList( {
);

const filteredBlockPatterns = useMemo( () => {
const filteredPatterns = allPatterns.filter( ( pattern ) => {
const filteredPatterns = patterns.filter( ( pattern ) => {
if (
isPatternFiltered(
pattern,
Expand Down Expand Up @@ -127,7 +127,7 @@ function PatternList( {
}, [
searchValue,
patternSourceFilter,
allPatterns,
patterns,
selectedCategory,
registeredPatternCategories,
patternSyncFilter,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,20 +74,20 @@ export function isPatternFiltered( pattern, sourceFilter, syncFilter ) {
}

export function usePatternsCategories( rootClientId, sourceFilter = 'all' ) {
const { patterns: allPatterns, allCategories } = usePatternsState(
const [ patterns, allCategories ] = usePatternsState(
undefined,
rootClientId
);

const filteredPatterns = useMemo(
() =>
sourceFilter === 'all'
? allPatterns
: allPatterns.filter(
? patterns
: patterns.filter(
( pattern ) =>
! isPatternFiltered( pattern, sourceFilter )
),
[ sourceFilter, allPatterns ]
[ sourceFilter, patterns ]
);

const hasRegisteredCategory = useCallback(
Expand Down Expand Up @@ -192,7 +192,7 @@ export function BlockPatternsCategoryPanel( {
showTitlesAsTooltip,
patternFilter,
} ) {
const { patterns: allPatterns, onClickPattern } = usePatternsState(
const [ allPatterns, , onClickPattern ] = usePatternsState(
onInsert,
rootClientId
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ const usePatternsState = ( onInsert, rootClientId ) => {
[ createSuccessNotice, onInsert ]
);

return { patterns, allCategories, onClickPattern };
return [ patterns, allCategories, onClickPattern ];
};

export default usePatternsState;
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export default function QuickInserter( {
onInsertBlocks
);

const { patterns } = usePatternsState(
const [ patterns ] = usePatternsState(
onInsertBlocks,
destinationRootClientId
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ function InserterSearchResults( {
blockTypeCollections,
onSelectBlockType,
] = useBlockTypesState( destinationRootClientId, onInsertBlocks );
const { patterns, onClickPattern } = usePatternsState(
const [ patterns, , onClickPattern ] = usePatternsState(
onInsertBlocks,
destinationRootClientId
);
Expand Down

0 comments on commit 23bb930

Please sign in to comment.