Skip to content

Commit

Permalink
Replace cards management controls for supernova inside query loops wi…
Browse files Browse the repository at this point in the history
…th simple Add Cards toolbar button #404
  • Loading branch information
razwan committed Jul 1, 2022
1 parent 380e56b commit 74045ae
Showing 1 changed file with 34 additions and 2 deletions.
36 changes: 34 additions & 2 deletions packages/block-library/src/blocks/supernova/block-controls.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { __ } from '@wordpress/i18n';
import { createBlock } from '@wordpress/blocks';
import { useCallback, useMemo } from '@wordpress/element';
import { Fragment, useCallback, useMemo } from '@wordpress/element';
import { addCard, gallery, plus } from '@wordpress/icons';

import {
Expand Down Expand Up @@ -31,8 +31,36 @@ import { compileSupernovaItemAttributes } from './utils';
const ALLOWED_MEDIA_TYPES = [ 'image', 'video' ];

const Controls = ( props ) => {
return (
<Fragment>
<QueryControls { ...props } />
<InnerBlocksControls { ...props } />
</Fragment>
)
}

const QueryControls = ( props ) => {
const { attributes, setAttributes, inQuery } = props;
const { postsToShow } = attributes;

if ( ! inQuery ) {
return null;
}

return (
<BlockControls>
<ToolbarGroup label={ __( 'Altceva', '__plugin_txtd' ) }>
<ToolbarButton onClick={ () => { setAttributes( { postsToShow: postsToShow + 1 } ); } }>
{ __( 'Add Cards', '__plugin_txtd' ) }
</ToolbarButton>
</ToolbarGroup>
</BlockControls>
)
}

const InnerBlocksControls = ( props ) => {

const { attributes, setAttributes, clientId } = props;
const { attributes, setAttributes, clientId, inQuery } = props;
const { align, postsToShow } = attributes;
const innerBlocks = useInnerBlocks( clientId );
const { replaceInnerBlocks, updateBlockAttributes } = useDispatch( 'core/block-editor' );
Expand Down Expand Up @@ -73,6 +101,10 @@ const Controls = ( props ) => {
replaceInnerBlocks( clientId, newInnerBlocks );
}, [ innerBlocks, postsToShow ] );

if ( inQuery ) {
return null;
}

return (
<BlockControls>
<ToolbarGroup label={ __( 'Layout', '__plugin_txtd' ) }>
Expand Down

0 comments on commit 74045ae

Please sign in to comment.