Skip to content

Commit 9a521f8

Browse files
committed
render all block patterns of the current page and remove async list
1 parent 0e587d5 commit 9a521f8

File tree

5 files changed

+15
-30
lines changed

5 files changed

+15
-30
lines changed

packages/block-editor/src/components/block-patterns-list/index.js

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ import { Icon, symbol } from '@wordpress/icons';
2323
*/
2424
import BlockPreview from '../block-preview';
2525
import InserterDraggableBlocks from '../inserter-draggable-blocks';
26-
import BlockPatternsPaging from '../block-patterns-paging';
2726
import { INSERTER_PATTERN_TYPES } from '../inserter/block-patterns-tab/utils';
2827

2928
const WithToolTip = ( { showTooltip, title, children } ) => {
@@ -177,25 +176,17 @@ function BlockPattern( {
177176
);
178177
}
179178

180-
function BlockPatternPlaceholder() {
181-
return (
182-
<div className="block-editor-block-patterns-list__item is-placeholder" />
183-
);
184-
}
185-
186179
function BlockPatternsList(
187180
{
188181
isDraggable,
189182
blockPatterns,
190-
shownPatterns,
191183
onHover,
192184
onClickPattern,
193185
orientation,
194186
label = __( 'Block patterns' ),
195187
category,
196188
showTitle = true,
197189
showTitlesAsTooltip,
198-
pagingProps,
199190
},
200191
ref
201192
) {
@@ -205,11 +196,9 @@ function BlockPatternsList(
205196
// Reset the active composite item whenever the available patterns change,
206197
// to make sure that Composite widget can receive focus correctly when its
207198
// composite items change. The first composite item will receive focus.
208-
const firstCompositeItemId = blockPatterns.find( ( pattern ) =>
209-
shownPatterns.includes( pattern )
210-
)?.name;
199+
const firstCompositeItemId = blockPatterns[ 0 ]?.name;
211200
setActiveCompositeId( firstCompositeItemId );
212-
}, [ shownPatterns, blockPatterns ] );
201+
}, [ blockPatterns ] );
213202

214203
return (
215204
<Composite
@@ -222,8 +211,7 @@ function BlockPatternsList(
222211
ref={ ref }
223212
>
224213
{ blockPatterns.map( ( pattern ) => {
225-
const isShown = shownPatterns.includes( pattern );
226-
return isShown ? (
214+
return (
227215
<BlockPattern
228216
key={ pattern.name }
229217
id={ pattern.name }
@@ -235,11 +223,8 @@ function BlockPatternsList(
235223
showTooltip={ showTitlesAsTooltip }
236224
category={ category }
237225
/>
238-
) : (
239-
<BlockPatternPlaceholder key={ pattern.name } />
240226
);
241227
} ) }
242-
{ pagingProps && <BlockPatternsPaging { ...pagingProps } /> }
243228
</Composite>
244229
);
245230
}

packages/block-editor/src/components/inserter/block-patterns-explorer/pattern-list.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -151,9 +151,6 @@ function PatternList( {
151151
{ hasItems && (
152152
<>
153153
<BlockPatternsList
154-
shownPatterns={
155-
pagingProps.categoryPatternsAsyncList
156-
}
157154
blockPatterns={ pagingProps.categoryPatterns }
158155
onClickPattern={ onClickPattern }
159156
isDraggable={ false }

packages/block-editor/src/components/inserter/block-patterns-tab/pattern-category-previews.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import { useSelect } from '@wordpress/data';
2424
*/
2525
import usePatternsState from '../hooks/use-patterns-state';
2626
import BlockPatternsList from '../../block-patterns-list';
27+
import BlockPatternsPaging from '../../block-patterns-paging';
2728
import usePatternsPaging from '../hooks/use-patterns-paging';
2829
import { PatternsFilter } from './patterns-filter';
2930
import { usePatternCategories } from './use-pattern-categories';
@@ -183,7 +184,6 @@ export function PatternCategoryPreviews( {
183184
) }
184185
<BlockPatternsList
185186
ref={ scrollContainerRef }
186-
shownPatterns={ pagingProps.categoryPatternsAsyncList }
187187
blockPatterns={ pagingProps.categoryPatterns }
188188
onClickPattern={ onClickPattern }
189189
onHover={ onHover }
@@ -193,8 +193,15 @@ export function PatternCategoryPreviews( {
193193
isDraggable
194194
showTitlesAsTooltip={ showTitlesAsTooltip }
195195
patternFilter={ patternSourceFilter }
196-
pagingProps={ pagingProps }
197196
/>
197+
{ pagingProps && (
198+
<VStack
199+
spacing={ 2 }
200+
className="block-editor-inserter__patterns-category-panel-footer"
201+
>
202+
<BlockPatternsPaging { ...pagingProps } />
203+
</VStack>
204+
) }
198205
</>
199206
) }
200207
</>

packages/block-editor/src/components/inserter/hooks/use-patterns-paging.js

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,10 @@
22
* WordPress dependencies
33
*/
44
import { useMemo, useState, useEffect } from '@wordpress/element';
5-
import { useAsyncList, usePrevious } from '@wordpress/compose';
5+
import { usePrevious } from '@wordpress/compose';
66
import { getScrollContainer } from '@wordpress/dom';
77

88
const PAGE_SIZE = 20;
9-
const INITIAL_INSERTER_RESULTS = 5;
109

1110
/**
1211
* Supplies values needed to page the patterns list client side.
@@ -42,9 +41,6 @@ export default function usePatternsPaging(
4241
pageIndex * PAGE_SIZE + PAGE_SIZE
4342
);
4443
}, [ pageIndex, currentCategoryPatterns ] );
45-
const categoryPatternsAsyncList = useAsyncList( categoryPatterns, {
46-
step: INITIAL_INSERTER_RESULTS,
47-
} );
4844
const numPages = Math.ceil( currentCategoryPatterns.length / PAGE_SIZE );
4945
const changePage = ( page ) => {
5046
const scrollContainer = getScrollContainer(
@@ -68,7 +64,6 @@ export default function usePatternsPaging(
6864
return {
6965
totalItems,
7066
categoryPatterns,
71-
categoryPatternsAsyncList,
7267
numPages,
7368
changePage,
7469
currentPage,

packages/block-editor/src/components/inserter/style.scss

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,8 @@ $block-inserter-tabs-height: 44px;
249249
}
250250
}
251251

252-
.block-editor-inserter__patterns-category-panel-header {
252+
.block-editor-inserter__patterns-category-panel-header,
253+
.block-editor-inserter__patterns-category-panel-footer {
253254
padding: $grid-unit-10 0;
254255
@include break-medium {
255256
padding: $grid-unit-10 $grid-unit-30;

0 commit comments

Comments
 (0)