PluginProbe
Smart Post – Post Grid, Post Carousel, Post Slider Gutenberg Blocks for Blog & News / 4.0.7
Smart Post – Post Grid, Post Carousel, Post Slider Gutenberg Blocks for Blog & News v4.0.7
4.0.8 4.0.7 4.0.6 4.0.5 4.0.4 4.0.3 4.0.2 4.0.1 2.3.5 2.3.6 2.4.0 2.4.1 2.4.10 2.4.11 2.4.12 2.4.13 2.4.14 2.4.15 2.4.16 2.4.17 2.4.18 2.4.19 2.4.2 2.4.20 2.4.21 All 88 releases
post-carousel / src / blocks / post-timeline-two / render.js

render.js in Smart Post – Post Grid, Post Carousel, Post Slider Gutenberg Blocks for Blog & News 4.0.7, at src/blocks/post-timeline-two/render.js

68 lines 2.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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