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