Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
15 changes: 13 additions & 2 deletions packages/edit-site/src/components/block-list-exploded/index.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,21 @@
/**
* WordPress dependencies
*/
import { store as blockEditorStore } from '@wordpress/block-editor';
import { store as blockEditorStore, Inserter } from '@wordpress/block-editor';
import { useSelect } from '@wordpress/data';
import { pure } from '@wordpress/compose';

/**
* Internal dependencies
*/
import BlockListExplodedItem from './item';

const InserterBeforeBlock = pure( ( { clientId } ) => (
Copy link
Member

Choose a reason for hiding this comment

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

I didn't know we had this HoC. Should I prefer using this over React.memo?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

To be honest at this point, I don't know. What's certain is that we need to make a decision :P. This HoC was here before React introduced React.memo and if I'm not wrong also works for Class component contrary to React.memo which I think is only suited for function components.

Copy link
Member

Choose a reason for hiding this comment

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

Right, React.memo works only with functional components.

What's certain is that we need to make a decision

Got it. Use React.memo with function components use pure with Class components 😄

<div className="edit-site-block-list-exploded__inserter" key={ clientId }>
<Inserter clientId={ clientId } __experimentalIsQuick isPrimary />
</div>
) );

function BlockListExploded() {
const blockOrder = useSelect( ( select ) => {
return select( blockEditorStore ).getBlockOrder();
Expand All @@ -17,8 +24,12 @@ function BlockListExploded() {
return (
<div className="edit-site-block-list-exploded">
{ blockOrder.map( ( clientId ) => (
<BlockListExplodedItem key={ clientId } clientId={ clientId } />
<div key={ clientId }>
<InserterBeforeBlock clientId={ clientId } />
<BlockListExplodedItem clientId={ clientId } />
</div>
) ) }
<InserterBeforeBlock />
</div>
);
}
Expand Down
59 changes: 23 additions & 36 deletions packages/edit-site/src/components/block-list-exploded/item.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import classnames from 'classnames';
import {
store as blockEditorStore,
BlockPreview,
Inserter,
useBlockDisplayInformation,
} from '@wordpress/block-editor';
import { useSelect, useDispatch } from '@wordpress/data';
Expand Down Expand Up @@ -52,43 +51,31 @@ function BlockListExplodedItem( { clientId } ) {
}, [ isSelected ] );

return (
<div>
<div
className={ classnames(
'edit-site-block-list-exploded__item-container',
{ 'is-selected': isSelected }
) }
>
{ isSelected && (
<BlockListExplodedTopToolbar clientId={ clientId } />
) }
<div
className="edit-site-block-list-exploded__inserter"
key={ block.clientId }
ref={ blockWrapper }
role="button"
onClick={ ( event ) => {
if ( event.detail === 1 ) {
selectBlock( clientId );
} else if ( event.detail === 2 ) {
switchEditorMode( 'visual' );
}
} }
onKeyPress={ () => selectBlock( clientId ) }
onFocus={ () => selectBlock( clientId ) }
aria-label={ blockLabel }
tabIndex={ 0 }
>
<Inserter
clientId={ block.clientId }
__experimentalIsQuick
isPrimary
/>
</div>
<div
className={ classnames(
'edit-site-block-list-exploded__item-container',
{ 'is-selected': isSelected }
) }
>
{ isSelected && (
<BlockListExplodedTopToolbar clientId={ clientId } />
) }
<div
ref={ blockWrapper }
role="button"
onClick={ ( event ) => {
if ( event.detail === 1 ) {
selectBlock( clientId );
} else if ( event.detail === 2 ) {
switchEditorMode( 'visual' );
}
} }
onKeyPress={ () => selectBlock( clientId ) }
onFocus={ () => selectBlock( clientId ) }
aria-label={ blockLabel }
tabIndex={ 0 }
>
<BlockPreview blocks={ blocksToPreview } />
</div>
<BlockPreview blocks={ blocksToPreview } />
</div>
</div>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
flex-direction: column;
width: $content-width;
margin: auto;
padding-bottom: 30px;
}

.edit-site-block-list-exploded__inserter > div {
Expand Down