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 / components / pagination / paginationWrapper.js

paginationWrapper.js in Smart Post – Post Grid, Post Carousel, Post Slider Gutenberg Blocks for Blog & News 4.0.7, at src/components/pagination/paginationWrapper.js

99 lines 2.9 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 { jsonParse } from "../../blocks/shared/helpFn";
3 import Pagination from "../../blocks/shared/templates/templates-parts/pagination";
4 import { usePaginationFn } from "./functionality";
5 import useApiData from "../../hooks/useApiData";
6 import useMetaData from "../../hooks/useMetaData";
7
8 export const EditorPaginationWrapper = ({ children }) => {
9 const { attributes, posts } = children?.props;
10 const { postCount } = useMetaData(attributes);
11 const { uniqueId, paginationEnable, navigationArrowPosition, paginationType } = jsonParse(attributes);
12
13 return (
14 <div id={uniqueId}>
15 {posts?.length > 0 && (
16 <>
17 {/* top pagination */}
18 {paginationEnable && paginationType === "navigation" && navigationArrowPosition === "top" && (
19 <Pagination attributes={attributes} />
20 )}
21 {/* render component */}
22 {children}
23 {/* bottom pagination */}
24 {paginationEnable && paginationType === "navigation" && navigationArrowPosition === "bottom" && (
25 <Pagination attributes={attributes} />
26 )}
27 {paginationEnable && paginationType !== "navigation" && (
28 <Pagination currentPage={1} postCount={postCount} attributes={attributes} />
29 )}
30 </>
31 )}
32 </div>
33 );
34 };
35
36 export const SavePaginationWrapper = ({ children, setPosts }) => {
37 const observerRef = useRef(null);
38 const ref = useRef(null);
39 const [currentPage, setCurrentPage] = useState(1);
40 const { attributes } = children?.props;
41 const parsedAttr = jsonParse(attributes);
42 const { paginationEnable, navigationArrowPosition, paginationType, uniqueId } = parsedAttr;
43 const { posts, postCount } = useApiData({
44 ...parsedAttr,
45 currentPage: currentPage,
46 });
47
48 const { allPosts } = usePaginationFn({
49 posts: posts,
50 postCount: postCount,
51 attributes: parsedAttr,
52 observerRef: observerRef,
53 ref: ref,
54 currentPage: currentPage,
55 setCurrentPage: setCurrentPage,
56 });
57
58 useEffect(() => {
59 setPosts(allPosts);
60 }, [allPosts]);
61
62 return (
63 <div id={uniqueId} ref={ref}>
64 {paginationEnable &&
65 paginationType === "navigation" &&
66 navigationArrowPosition === "top" &&
67 posts?.length > 0 && (
68 <Pagination
69 postCount={postCount}
70 attributes={attributes}
71 currentPage={currentPage}
72 setCurrentPage={setCurrentPage}
73 />
74 )}
75 {children}
76 {paginationEnable &&
77 paginationType === "navigation" &&
78 navigationArrowPosition === "bottom" &&
79 posts?.length > 0 && (
80 <Pagination
81 postCount={postCount}
82 attributes={attributes}
83 currentPage={currentPage}
84 setCurrentPage={setCurrentPage}
85 />
86 )}
87 {paginationEnable && paginationType !== "navigation" && posts?.length > 0 && (
88 <Pagination
89 postCount={postCount}
90 attributes={attributes}
91 currentPage={currentPage}
92 setCurrentPage={setCurrentPage}
93 />
94 )}
95 <div ref={observerRef}></div>
96 </div>
97 );
98 };
99