D7net
Home
Console
Upload
information
Create File
Create Folder
About
Tools
:
/
var
/
softaculous
/
sitepad
/
editor
/
site-data
/
plugins
/
pagelayer
/
js
/
react
/
src
/
blocks
/
Filename :
review_slider.js
back
Copy
import { useEffect, useState } from '@wordpress/element'; import { select } from '@wordpress/data'; import { RenderGroupBlock } from './render-group'; export const RenderReviewSliderBlock = (props) =>{ const { _props, data } = props; const { attributes, clientId } = _props; const { id, tag} = data; const [ preChildCount, setPreChildCount ] = useState(0); const [ refreshSlider, setRefreshSlider ] = useState(false); const hasChildrens = select( 'core/block-editor' ).getBlocks( clientId ).length; const renderSlider = () =>{ let jEle = pagelayer_query(`.p-${id}`); pagelayer_owl_destroy(jEle, '.pagelayer-reviews-holder'); pagelayer_reviews_slider(jEle); } // For the insert and drag new child if(preChildCount != hasChildrens){ let jEle = pagelayer_query(`.p-${id}`); pagelayer_owl_destroy(jEle, '.pagelayer-reviews-holder'); setPreChildCount(hasChildrens); } useEffect(() => { setTimeout(renderSlider, 200); }, [attributes]); useEffect(renderSlider, [hasChildrens, refreshSlider]); useEffect(() => { var jEle = pagelayer_query(`.p-${id}`); jEle.find('.pagelayer-owl-carousel').on('refresh.pagelayer.owl', function(){ setRefreshSlider(!refreshSlider); }); if(jEle.find('.pagelayer-reviews-holder > .pagelayer-owl-stage-outer').length < 1){ renderSlider(); } return (() => { jEle.find('.pagelayer-owl-carousel').unbind('refresh.pagelayer.owl'); }); }); var elementProps = { plTag: tag, _props: _props, }; return ( <> <div className="pagelayer-review-slides-container"> <RenderGroupBlock className="pagelayer-reviews-holder pagelayer-owl-holder pagelayer-owl-carousel pagelayer-owl-theme" {...elementProps} /> </div> </> ); }