PluginProbe
Smart Post – Post Grid, Post Carousel, Post Slider Gutenberg Blocks for Blog & News / 4.0.8
Smart Post – Post Grid, Post Carousel, Post Slider Gutenberg Blocks for Blog & News v4.0.8
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-grid-six / loopContent.js

loopContent.js in Smart Post – Post Grid, Post Carousel, Post Slider Gutenberg Blocks for Blog & News 4.0.8, at src/blocks/post-grid-six/loopContent.js

131 lines 3.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 import { Fragment, useEffect, useState } from "@wordpress/element";
2 import TemplateOne from "../shared/templates/templateCards/templateOne";
3 import { breakpoint, inArray } from "../../controls/controls";
4
5 const LoopContent = ({
6 posts,
7 attributes,
8 bottomStyle = false,
9 layoutStyle = "grid-six-layout-four",
10 containerVAlign = false,
11 horizontalAlign = false,
12 Masonry = false,
13 ResponsiveMasonry = Fragment,
14 containerRef,
15 }) => {
16 const { postGridLayout, contentVerticalPosition, gridSixColumns, masonryGap } = attributes;
17
18 const deviceType = breakpoint();
19
20 const largeItemsNumber =
21 "Mobile" !== deviceType ? (inArray(["grid-six-layout-one", "grid-six-layout-two"], postGridLayout) ? 1 : 2) : 0;
22
23 const masonryGapCss = `${masonryGap?.device?.Desktop}${masonryGap?.unit?.Desktop}`;
24
25 const columnsBreakPoints = Masonry
26 ? {
27 columnsCountBreakPoints: {
28 350: gridSixColumns?.device?.Mobile,
29 750: gridSixColumns?.device?.Tablet,
30 900: gridSixColumns?.device?.Desktop,
31 },
32 }
33 : {};
34
35 const gutter = Masonry
36 ? {
37 gutter: masonryGapCss,
38 }
39 : {};
40 const [selectedPostId, setSelectedPostId] = useState(null);
41
42 useEffect(() => {
43 const handleClickOutside = (event) => {
44 if (containerRef.current && !containerRef.current.contains(event.target)) {
45 setSelectedPostId(null);
46 }
47 const targetPostId = parseInt(event.target.closest(".sp-smart-post-card-image")?.dataset?.post_id);
48 if (targetPostId && targetPostId !== selectedPostId) {
49 setSelectedPostId(null);
50 }
51 };
52
53 document.addEventListener("mousedown", handleClickOutside);
54 return () => document.removeEventListener("mousedown", handleClickOutside);
55 }, [selectedPostId]);
56
57 return (
58 <>
59 {Masonry && (
60 <ResponsiveMasonry {...columnsBreakPoints}>
61 <Masonry {...gutter}>
62 {posts
63 ?.slice(bottomStyle ? largeItemsNumber : 0, bottomStyle ? posts?.length : largeItemsNumber)
64 ?.map(
65 (post) => (
66 // postGridLayout === layoutStyle ? (
67 <TemplateOne
68 key={post?.post_id}
69 data={post}
70 posts={posts}
71 containerVAlign={containerVAlign}
72 horizontalAlign={horizontalAlign}
73 attributes={attributes}
74 contentPosition={contentVerticalPosition}
75 isSelected={selectedPostId === post?.post_id}
76 onSelect={() => setSelectedPostId(post?.post_id)}
77 />
78 )
79 // ) : (
80 // <TemplateOne
81 // key={ post?.post_id }
82 // data={ post }
83 // posts={ posts }
84 // attributes={
85 // attributes
86 // }
87 // contentPosition={
88 // contentVerticalPosition
89 // }
90 // isSelected={ selectedPostId === post?.post_id }
91 // onSelect={ () => setSelectedPostId( post?.post_id ) }
92 // />
93 // )
94 )}
95 </Masonry>
96 </ResponsiveMasonry>
97 )}
98 {!Masonry &&
99 posts?.slice(bottomStyle ? largeItemsNumber : 0, bottomStyle ? posts?.length : largeItemsNumber)?.map(
100 (post) => (
101 // postGridLayout === layoutStyle ? (
102 <TemplateOne
103 key={post?.post_id}
104 data={post}
105 posts={posts}
106 containerVAlign={containerVAlign}
107 horizontalAlign={horizontalAlign}
108 attributes={attributes}
109 contentPosition={contentVerticalPosition}
110 isSelected={selectedPostId === post?.post_id}
111 onSelect={() => setSelectedPostId(post?.post_id)}
112 />
113 )
114 // ) : (
115 // <TemplateOne
116 // key={ post?.post_id }
117 // data={ post }
118 // posts={ posts }
119 // attributes={ attributes }
120 // contentPosition={ contentVerticalPosition }
121 // isSelected={ selectedPostId === post?.post_id }
122 // onSelect={ () => setSelectedPostId( post?.post_id ) }
123 // />
124 // )
125 )}
126 </>
127 );
128 };
129
130 export default LoopContent;
131