edit.js (1589B)
1 /** 2 * External dependencies. 3 */ 4 import { ReduxTemplatesIcon } from '~redux-templates/icons' 5 // import { ModalDesignLibrary } from '~stackable/components' 6 import {ModalManager} from '../../modal-manager'; 7 import LibraryModal from '../../modal-library'; 8 9 /** 10 * WordPress dependencies. 11 */ 12 import { 13 Button, Placeholder, 14 } from '@wordpress/components' 15 import { compose } from '@wordpress/compose' 16 import { createBlock, parse } from '@wordpress/blocks' 17 import { withDispatch } from '@wordpress/data' 18 import { useState } from '@wordpress/element' 19 import { __ } from '@wordpress/i18n' 20 import { applyFilters } from '@wordpress/hooks' 21 22 const edit = ( { removeLibraryBlock, preview } ) => { 23 if (preview) { 24 alert('here i am'); 25 } 26 27 return ( 28 <div className="redux-template-library-block"> 29 <Placeholder 30 icon={ <ReduxTemplatesIcon /> } 31 label={ __( 'Redux Template Library', redux_templates.i18n ) } 32 instructions={ __( 'Open the Design Library and select a pre-designed block or layout.', redux_templates.i18n ) } 33 > 34 <Button 35 isSecondary 36 isLarge 37 hasIcon 38 className="redux-template-library-block__button" 39 onClick={ () => { 40 ModalManager.open(<LibraryModal />); 41 removeLibraryBlock() 42 } } 43 >{ __( 'Open Design Library', redux_templates.i18n ) }</Button> 44 </Placeholder> 45 </div> 46 ) 47 } 48 49 export default compose( [ 50 withDispatch( ( dispatch, { 51 clientId, 52 } ) => { 53 const { removeBlocks } = dispatch( 'core/block-editor' ) 54 return { 55 removeLibraryBlock: serializedBlock => { 56 removeBlocks( clientId ); 57 }, 58 } 59 } ), 60 ] )( edit )