| 1 |
import { useEffect, useRef, useState } from "@wordpress/element"; |
| 2 |
import { toggleEqualHeight } from "../shared/helpFn"; |
| 3 |
import TemplateOne from "../shared/templates/templateCards/templateOne"; |
| 4 |
import { breakpoint, inArray } from "../../controls/controls"; |
| 5 |
|
| 6 |
const Render = ({ attributes, posts }) => { |
| 7 |
const { |
| 8 |
timelineLayout, |
| 9 |
uniqueId, |
| 10 |
equalHeightEnable, |
| 11 |
imagePosition, |
| 12 |
contentOrientation, |
| 13 |
postGridLayout, |
| 14 |
catTabCategoryPosition, |
| 15 |
} = attributes; |
| 16 |
const containerRef = useRef(null); |
| 17 |
|
| 18 |
useEffect(() => { |
| 19 |
setTimeout(() => { |
| 20 |
toggleEqualHeight(uniqueId, equalHeightEnable); |
| 21 |
}, 50); |
| 22 |
}, [equalHeightEnable, uniqueId, posts]); |
| 23 |
|
| 24 |
const [selectedPostId, setSelectedPostId] = useState(null); |
| 25 |
|
| 26 |
useEffect(() => { |
| 27 |
const handleClickOutside = (event) => { |
| 28 |
if (containerRef.current && !containerRef.current.contains(event.target)) { |
| 29 |
setSelectedPostId(null); |
| 30 |
} |
| 31 |
}; |
| 32 |
|
| 33 |
document.addEventListener("mousedown", handleClickOutside); |
| 34 |
return () => document.removeEventListener("mousedown", handleClickOutside); |
| 35 |
}, []); |
| 36 |
|
| 37 |
return ( |
| 38 |
<div |
| 39 |
className={`sp-smart-post-wrapper post-timeline-one sp-smart-post-show-scroll-wrapper template-one img-position-${imagePosition} ${contentOrientation} sp-cat-position-${catTabCategoryPosition}`} |
| 40 |
id={uniqueId} |
| 41 |
ref={containerRef} |
| 42 |
> |
| 43 |
<div |
| 44 |
className={`sp-smart-post-timeline-container ${ |
| 45 |
breakpoint() === "Mobile" && !inArray(["timeline-one-layout-six"], timelineLayout) |
| 46 |
? "timeline-one-layout-five" |
| 47 |
: timelineLayout |
| 48 |
}`} |
| 49 |
> |
| 50 |
{posts?.map((post) => { |
| 51 |
return ( |
| 52 |
<div key={post?.post_id} className="sp-smart-post-timeline-one-post-container"> |
| 53 |
<div className="sp-smart-indicator"> |
| 54 |
<div className="sp-smart-indicator-circle"></div> |
| 55 |
<div className="sp-smart-indicator-arrow"></div> |
| 56 |
</div> |
| 57 |
<TemplateOne |
| 58 |
data={post} |
| 59 |
attributes={attributes} |
| 60 |
posts={posts} |
| 61 |
isSelected={selectedPostId === post?.post_id} |
| 62 |
onSelect={() => setSelectedPostId(post?.post_id)} |
| 63 |
/> |
| 64 |
</div> |
| 65 |
); |
| 66 |
})} |
| 67 |
</div> |
| 68 |
</div> |
| 69 |
); |
| 70 |
}; |
| 71 |
|
| 72 |
export default Render; |
| 73 |
|