Skip to content

Commit

Permalink
Replaced insertBlock with replaceInnerBlocks.
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolad committed Jun 30, 2019
1 parent 29f6ead commit 792401a
Showing 1 changed file with 18 additions and 10 deletions.
28 changes: 18 additions & 10 deletions packages/block-library/src/social-links/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ export const SocialLinksEdit = function( { attributes, setAttributes, className,
isLarge
label={ __( 'Add link' ) }
icon="insert"
onClick={ () => addLink() } >
onClick={ addLink } >
{ __( 'Add link' ) }
</IconButton>
</div>
Expand All @@ -98,19 +98,27 @@ const DEFAULT_EMPTY_ARRAY = [];

export default compose(
withSelect( ( select, { clientId } ) => {
const { getBlocksByClientId } = select( 'core/editor' );
const { getBlocksByClientId } = select( 'core/block-editor' );
const [ block ] = getBlocksByClientId( clientId );

return {
childLinks: block ? block.innerBlocks : DEFAULT_EMPTY_ARRAY,
};
} ),
withDispatch( ( dispatch, { clientId, childLinks } ) => {
return {
addLink() {
const created = createBlock( 'core/social-link', { verticalAlignment: 'top' } );
dispatch( 'core/editor' ).insertBlock( created, undefined, clientId );
},
};
} ),
withDispatch( ( dispatch, ownProps, registry ) => ( {
addLink() {
const { clientId } = ownProps;
const { replaceInnerBlocks } = dispatch( 'core/block-editor' );
const { getBlocks } = registry.select( 'core/block-editor' );

let innerBlocks = getBlocks( clientId );
innerBlocks = [
...innerBlocks,
createBlock( 'core/social-link', { verticalAlignment: 'top' } ),
];

replaceInnerBlocks( clientId, innerBlocks, false );
},
} )
),
)( SocialLinksEdit );

0 comments on commit 792401a

Please sign in to comment.