| 1 |
import { memo, useEffect, useRef } from "@wordpress/element"; |
| 2 |
import { availableLargeContent } from "../../controls/constants"; |
| 3 |
import { toggleEqualHeight } from "../shared/helpFn"; |
| 4 |
import LoopContent from "./loopContent"; |
| 5 |
import { breakpoint } from "../../controls/controls"; |
| 6 |
|
| 7 |
const Render = ({ attributes, posts }) => { |
| 8 |
const { |
| 9 |
postGridLayout, |
| 10 |
uniqueId, |
| 11 |
gridLargeContentPosition, |
| 12 |
equalHeightEnable, |
| 13 |
imagePosition, |
| 14 |
contentOrientation, |
| 15 |
catTabCategoryPosition, |
| 16 |
// gridOneMasonryEnable, |
| 17 |
} = attributes; |
| 18 |
|
| 19 |
const deviceType = breakpoint(); |
| 20 |
|
| 21 |
const isAvailableLargeItem = availableLargeContent.includes(postGridLayout); |
| 22 |
|
| 23 |
const largeContentPositionClass = isAvailableLargeItem ? gridLargeContentPosition : ""; |
| 24 |
|
| 25 |
useEffect(() => { |
| 26 |
setTimeout(() => { |
| 27 |
toggleEqualHeight(uniqueId, equalHeightEnable); |
| 28 |
}, 50); |
| 29 |
}, [equalHeightEnable, uniqueId, posts]); |
| 30 |
|
| 31 |
const ref = useRef(null); |
| 32 |
|
| 33 |
useEffect(() => { |
| 34 |
const style = ref.current.style; |
| 35 |
style.transition = "0.1s"; |
| 36 |
style.opacity = "0.5"; |
| 37 |
}, []); |
| 38 |
|
| 39 |
useEffect(() => { |
| 40 |
const style = ref.current.style; |
| 41 |
|
| 42 |
if (posts?.length > 1) { |
| 43 |
setTimeout(() => { |
| 44 |
style.height = ``; |
| 45 |
}, 200); |
| 46 |
} |
| 47 |
|
| 48 |
setTimeout(() => { |
| 49 |
style.opacity = "1"; |
| 50 |
}, 300); |
| 51 |
}, [posts]); |
| 52 |
|
| 53 |
const HtmlTag = "div"; |
| 54 |
|
| 55 |
const catePositionClass = catTabCategoryPosition ? ` sp-cat-position-${catTabCategoryPosition}` : ""; |
| 56 |
|
| 57 |
return ( |
| 58 |
<div |
| 59 |
ref={ref} |
| 60 |
className={`grid-one-container template-one img-position-${imagePosition} ${contentOrientation} ${postGridLayout} ${largeContentPositionClass}${catePositionClass}`} |
| 61 |
> |
| 62 |
<HtmlTag className={`sp-smart-post-dynamic-grid-contents`}> |
| 63 |
<LoopContent |
| 64 |
bottomStyle={true} |
| 65 |
deviceType={deviceType} |
| 66 |
posts={posts} |
| 67 |
attributes={attributes} |
| 68 |
containerRef={ref} |
| 69 |
/> |
| 70 |
</HtmlTag> |
| 71 |
</div> |
| 72 |
); |
| 73 |
}; |
| 74 |
|
| 75 |
export default memo(Render); |
| 76 |
|