Skip to content

Commit

Permalink
Small fixes for new cards management controls - #404
Browse files Browse the repository at this point in the history
  • Loading branch information
razwan committed Jul 5, 2022
1 parent e2d85cb commit 07a1e25
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,16 @@ const SupernovaItemBlockControls = ( props ) => {
return null;
}, [ clientId ] );

const innerBlocks = useInnerBlocks( clientId );
const parentInnerBlocks = useInnerBlocks( parentClientId );

const addNewCard = useCallback( () => {
const newInnerBlocks = parentInnerBlocks.slice();
const index = newInnerBlocks.findIndex( block => block.clientId === clientId );
const newBlock = createBlock( 'novablocks/supernova-item', attributes );
const newBlock = createBlock( 'novablocks/supernova-item', attributes, innerBlocks );
newInnerBlocks.splice( index + 1, 0, newBlock );
replaceInnerBlocks( parentClientId, newInnerBlocks );
}, [ clientId, parentClientId, attributes ] );
}, [ clientId, innerBlocks, parentClientId, attributes ] );

return (
<BlockControls>
Expand Down
7 changes: 5 additions & 2 deletions packages/block-library/src/blocks/supernova/block-controls.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,10 @@ const InnerBlocksControls = ( props ) => {

const addNewCard = useCallback( () => {
const newInnerBlocks = innerBlocks.slice();
const newBlockAttributes = innerBlocks[ innerBlocks.length - 1 ].attributes;
const newBlock = createBlock( 'novablocks/supernova-item', newBlockAttributes );
const lastBlock = innerBlocks[ innerBlocks.length - 1 ];
const newBlockAttributes = lastBlock.attributes;
const newBlockInnerBlocks = lastBlock.innerBlocks;
const newBlock = createBlock( 'novablocks/supernova-item', newBlockAttributes, newBlockInnerBlocks );
newInnerBlocks.push( newBlock );
replaceInnerBlocks( clientId, newInnerBlocks );
}, [ innerBlocks, postsToShow ] );
Expand Down Expand Up @@ -147,6 +149,7 @@ const InnerBlocksControls = ( props ) => {
<MenuGroup>
<MediaUpload
allowedTypes={ ALLOWED_MEDIA_TYPES }
gallery
multiple
value={ [] }
onSelect={ onSelectImages }
Expand Down

0 comments on commit 07a1e25

Please sign in to comment.