From b03ed42e16706b0b88341bd5bd443464f9acc930 Mon Sep 17 00:00:00 2001 From: Glen Davies Date: Tue, 19 Sep 2023 15:21:49 +1200 Subject: [PATCH] Revert usePatternsState to return an array instead of an object --- .../inserter/block-patterns-explorer/patterns-list.js | 6 +++--- .../src/components/inserter/block-patterns-tab.js | 10 +++++----- .../components/inserter/hooks/use-patterns-state.js | 2 +- .../src/components/inserter/quick-inserter.js | 2 +- .../src/components/inserter/search-results.js | 2 +- 5 files changed, 11 insertions(+), 11 deletions(-) diff --git a/packages/block-editor/src/components/inserter/block-patterns-explorer/patterns-list.js b/packages/block-editor/src/components/inserter/block-patterns-explorer/patterns-list.js index a33ceba422f686..32f52dd5c38188 100644 --- a/packages/block-editor/src/components/inserter/block-patterns-explorer/patterns-list.js +++ b/packages/block-editor/src/components/inserter/block-patterns-explorer/patterns-list.js @@ -74,7 +74,7 @@ function PatternList( { const [ destinationRootClientId, onInsertBlocks ] = useInsertionPoint( { shouldFocusBlock: true, } ); - const { patterns: allPatterns, onClickPattern } = usePatternsState( + const [ patterns, , onClickPattern ] = usePatternsState( onInsertBlocks, destinationRootClientId ); @@ -88,7 +88,7 @@ function PatternList( { ); const filteredBlockPatterns = useMemo( () => { - const filteredPatterns = allPatterns.filter( ( pattern ) => { + const filteredPatterns = patterns.filter( ( pattern ) => { if ( isPatternFiltered( pattern, @@ -127,7 +127,7 @@ function PatternList( { }, [ searchValue, patternSourceFilter, - allPatterns, + patterns, selectedCategory, registeredPatternCategories, patternSyncFilter, diff --git a/packages/block-editor/src/components/inserter/block-patterns-tab.js b/packages/block-editor/src/components/inserter/block-patterns-tab.js index 8e29567343fee5..37192df28a23bc 100644 --- a/packages/block-editor/src/components/inserter/block-patterns-tab.js +++ b/packages/block-editor/src/components/inserter/block-patterns-tab.js @@ -74,7 +74,7 @@ export function isPatternFiltered( pattern, sourceFilter, syncFilter ) { } export function usePatternsCategories( rootClientId, sourceFilter = 'all' ) { - const { patterns: allPatterns, allCategories } = usePatternsState( + const [ patterns, allCategories ] = usePatternsState( undefined, rootClientId ); @@ -82,12 +82,12 @@ export function usePatternsCategories( rootClientId, sourceFilter = 'all' ) { const filteredPatterns = useMemo( () => sourceFilter === 'all' - ? allPatterns - : allPatterns.filter( + ? patterns + : patterns.filter( ( pattern ) => ! isPatternFiltered( pattern, sourceFilter ) ), - [ sourceFilter, allPatterns ] + [ sourceFilter, patterns ] ); const hasRegisteredCategory = useCallback( @@ -192,7 +192,7 @@ export function BlockPatternsCategoryPanel( { showTitlesAsTooltip, patternFilter, } ) { - const { patterns: allPatterns, onClickPattern } = usePatternsState( + const [ allPatterns, , onClickPattern ] = usePatternsState( onInsert, rootClientId ); diff --git a/packages/block-editor/src/components/inserter/hooks/use-patterns-state.js b/packages/block-editor/src/components/inserter/hooks/use-patterns-state.js index 0c938b0474a9fa..90d67ccf12190c 100644 --- a/packages/block-editor/src/components/inserter/hooks/use-patterns-state.js +++ b/packages/block-editor/src/components/inserter/hooks/use-patterns-state.js @@ -80,7 +80,7 @@ const usePatternsState = ( onInsert, rootClientId ) => { [ createSuccessNotice, onInsert ] ); - return { patterns, allCategories, onClickPattern }; + return [ patterns, allCategories, onClickPattern ]; }; export default usePatternsState; diff --git a/packages/block-editor/src/components/inserter/quick-inserter.js b/packages/block-editor/src/components/inserter/quick-inserter.js index d75b45564246e5..540b51a4757e0d 100644 --- a/packages/block-editor/src/components/inserter/quick-inserter.js +++ b/packages/block-editor/src/components/inserter/quick-inserter.js @@ -46,7 +46,7 @@ export default function QuickInserter( { onInsertBlocks ); - const { patterns } = usePatternsState( + const [ patterns ] = usePatternsState( onInsertBlocks, destinationRootClientId ); diff --git a/packages/block-editor/src/components/inserter/search-results.js b/packages/block-editor/src/components/inserter/search-results.js index 46cacb17846479..23a3cafc563ba6 100644 --- a/packages/block-editor/src/components/inserter/search-results.js +++ b/packages/block-editor/src/components/inserter/search-results.js @@ -81,7 +81,7 @@ function InserterSearchResults( { blockTypeCollections, onSelectBlockType, ] = useBlockTypesState( destinationRootClientId, onInsertBlocks ); - const { patterns, onClickPattern } = usePatternsState( + const [ patterns, , onClickPattern ] = usePatternsState( onInsertBlocks, destinationRootClientId );