Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Render all block patterns of the current page and remove async list #66114

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import { Icon, symbol } from '@wordpress/icons';
*/
import BlockPreview from '../block-preview';
import InserterDraggableBlocks from '../inserter-draggable-blocks';
import BlockPatternsPaging from '../block-patterns-paging';
import { INSERTER_PATTERN_TYPES } from '../inserter/block-patterns-tab/utils';

const WithToolTip = ( { showTooltip, title, children } ) => {
Expand Down Expand Up @@ -177,25 +176,17 @@ function BlockPattern( {
);
}

function BlockPatternPlaceholder() {
return (
<div className="block-editor-block-patterns-list__item is-placeholder" />
);
}

function BlockPatternsList(
{
isDraggable,
blockPatterns,
shownPatterns,
onHover,
onClickPattern,
orientation,
label = __( 'Block patterns' ),
category,
showTitle = true,
showTitlesAsTooltip,
pagingProps,
},
ref
) {
Expand All @@ -205,11 +196,9 @@ function BlockPatternsList(
// Reset the active composite item whenever the available patterns change,
// to make sure that Composite widget can receive focus correctly when its
// composite items change. The first composite item will receive focus.
const firstCompositeItemId = blockPatterns.find( ( pattern ) =>
shownPatterns.includes( pattern )
)?.name;
const firstCompositeItemId = blockPatterns[ 0 ]?.name;
setActiveCompositeId( firstCompositeItemId );
}, [ shownPatterns, blockPatterns ] );
}, [ blockPatterns ] );

return (
<Composite
Expand All @@ -222,8 +211,7 @@ function BlockPatternsList(
ref={ ref }
>
{ blockPatterns.map( ( pattern ) => {
const isShown = shownPatterns.includes( pattern );
return isShown ? (
return (
<BlockPattern
key={ pattern.name }
id={ pattern.name }
Expand All @@ -235,11 +223,8 @@ function BlockPatternsList(
showTooltip={ showTitlesAsTooltip }
category={ category }
/>
) : (
<BlockPatternPlaceholder key={ pattern.name } />
);
} ) }
{ pagingProps && <BlockPatternsPaging { ...pagingProps } /> }
</Composite>
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,9 +151,6 @@ function PatternList( {
{ hasItems && (
<>
<BlockPatternsList
shownPatterns={
pagingProps.categoryPatternsAsyncList
}
blockPatterns={ pagingProps.categoryPatterns }
onClickPattern={ onClickPattern }
isDraggable={ false }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import { useSelect } from '@wordpress/data';
*/
import usePatternsState from '../hooks/use-patterns-state';
import BlockPatternsList from '../../block-patterns-list';
import BlockPatternsPaging from '../../block-patterns-paging';
import usePatternsPaging from '../hooks/use-patterns-paging';
import { PatternsFilter } from './patterns-filter';
import { usePatternCategories } from './use-pattern-categories';
Expand Down Expand Up @@ -183,7 +184,6 @@ export function PatternCategoryPreviews( {
) }
<BlockPatternsList
ref={ scrollContainerRef }
shownPatterns={ pagingProps.categoryPatternsAsyncList }
blockPatterns={ pagingProps.categoryPatterns }
onClickPattern={ onClickPattern }
onHover={ onHover }
Expand All @@ -193,8 +193,15 @@ export function PatternCategoryPreviews( {
isDraggable
showTitlesAsTooltip={ showTitlesAsTooltip }
patternFilter={ patternSourceFilter }
pagingProps={ pagingProps }
/>
{ pagingProps && (
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unless critical to this PR, then I'd suggest we take the changes that move Pagination and put in a separate PR.

<VStack
spacing={ 2 }
className="block-editor-inserter__patterns-category-panel-footer"
>
<BlockPatternsPaging { ...pagingProps } />
</VStack>
) }
</>
) }
</>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@
* WordPress dependencies
*/
import { useMemo, useState, useEffect } from '@wordpress/element';
import { useAsyncList, usePrevious } from '@wordpress/compose';
import { usePrevious } from '@wordpress/compose';
import { getScrollContainer } from '@wordpress/dom';

const PAGE_SIZE = 20;
const INITIAL_INSERTER_RESULTS = 5;

/**
* Supplies values needed to page the patterns list client side.
Expand Down Expand Up @@ -42,9 +41,6 @@ export default function usePatternsPaging(
pageIndex * PAGE_SIZE + PAGE_SIZE
);
}, [ pageIndex, currentCategoryPatterns ] );
const categoryPatternsAsyncList = useAsyncList( categoryPatterns, {
step: INITIAL_INSERTER_RESULTS,
} );
const numPages = Math.ceil( currentCategoryPatterns.length / PAGE_SIZE );
const changePage = ( page ) => {
const scrollContainer = getScrollContainer(
Expand All @@ -68,7 +64,6 @@ export default function usePatternsPaging(
return {
totalItems,
categoryPatterns,
categoryPatternsAsyncList,
numPages,
changePage,
currentPage,
Expand Down
3 changes: 2 additions & 1 deletion packages/block-editor/src/components/inserter/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,8 @@ $block-inserter-tabs-height: 44px;
}
}

.block-editor-inserter__patterns-category-panel-header {
.block-editor-inserter__patterns-category-panel-header,
.block-editor-inserter__patterns-category-panel-footer {
padding: $grid-unit-10 0;
@include break-medium {
padding: $grid-unit-10 $grid-unit-30;
Expand Down
Loading