PluginProbe
BlockSpare – Gutenberg Blocks for News, Magazine, Blog & Business Websites / 3.3.3
BlockSpare – Gutenberg Blocks for News, Magazine, Blog & Business Websites v3.3.3
4.1.0 trunk 1.0.0 1.0.1 1.0.2 1.0.3 1.0.4 1.0.5 1.1.0 1.1.1 1.1.2 1.2.0 1.2.1 1.2.2 1.2.3 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 1.3.5 2.1.2 2.5.0 2.5.3 2.6.1 All 38 releases
blockspare / admin / pages / demo / sections.js

sections.js in BlockSpare – Gutenberg Blocks for News, Magazine, Blog & Business Websites 3.3.3, at admin/pages/demo/sections.js

131 lines 5.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 import React, { useState, useEffect } from 'react'
2 const { __ } = wp.i18n;
3 import Copycontent from "./copy-content"
4 import Masonry from 'react-masonry-component';
5 import CreateBlockButton from './create-block-button';
6 import PremiumText from "./premium-text"
7 import icons from '../../../src/assets/icons';
8 const Sections = ({ data }) => {
9 const [isLoading, setISLoading] = useState(false)
10 const [visibleItems, setVisibleItems] = useState(10)
11 const [sections, setSections] = useState([]);
12 useEffect(() => {
13 if (data) {
14 const sections = Object.values(data)
15 .filter(item => item.type === 'section')
16 .sort((a, b) => {
17 if (a.name < b.name) {
18 return -1;
19 }
20 if (a.name > b.name) {
21 return 1;
22 }
23 return 0;
24 });
25 setISLoading(true)
26 setSections(sections)
27 }
28 }, [data]);
29
30 const masonryOptions = {
31 transitionDuration: 0,
32 percentPosition: true,
33 };
34
35
36 useEffect(() => {
37 const handleScroll = () => {
38 const container = document.getElementById('bs-blockpages');
39 const scrollY = container.scrollTop;
40 const containerHeight = container.clientHeight;
41 const contentHeight = container.scrollHeight;
42
43 if (scrollY + containerHeight >= contentHeight - 200) {
44 // Adjust the value (200) as needed to trigger the load more function earlier or later
45 loadVisibleItems();
46 }
47 };
48
49 const container = document.getElementById('bs-blockpages');
50 container.addEventListener('scroll', handleScroll);
51
52 return () => {
53 container.removeEventListener('scroll', handleScroll);
54 };
55 }, [visibleItems]);
56
57
58 const loadVisibleItems = () => {
59 const itemsPerPage = 10;
60 setVisibleItems(prevVisibleItems => prevVisibleItems + itemsPerPage);
61 };
62
63 return (
64
65 <div className='bs-layouts-wrappper' id="bs-blockpages">
66 {isLoading ? <Masonry
67 elementType={'div'}
68 className={`bs-layout-choices`}
69 options={masonryOptions}
70 disableImagesLoaded={false}
71 updateOnEachImageLoad={false}
72 >
73 {sections &&
74 sections.slice(0, visibleItems).map((item, i) => {
75 const nameInLowerCase = item.name.toLowerCase();
76 const imageName = nameInLowerCase.replace(/\s+/g, '-');
77 const folderName = item.imagePath
78 return (
79
80 <div className='bs-layout-design'>
81 <div className="bs-layout-design-inside">
82 <div className='bs-layout-design-item'>
83 <a href={item.content === 'https://www.blockspare.com/' ? 'javascript:void(0);' : item.blockLink} target={item.content === 'https://www.blockspare.com/' ? '_self' : '_blank'} className="bs-layout-insert-button" >
84 {
85 item.content === 'https://www.blockspare.com/' ? (
86 <PremiumText link={item.blockLink} />
87 ) : (
88 <div className="bs-layout-image-overlay">
89 <span className="bs-layout-action-info">
90 {icons.view}
91 {__('View', 'blockspare')}
92 </span>
93 </div>
94 )
95 }
96 <img
97 src={blockspare_dashboard.imagePath + folderName + "/" + imageName + ".jpg"}
98 alt={item.name}
99 />
100 </a>
101 <div className='bs-layout-design-info'>
102 <div className='bs-layout-design-title'>{item.name}</div>
103
104 {item.content !== 'https://www.blockspare.com/' &&
105 <div className='bs-layout-actions'>
106 <CreateBlockButton href={blockspare_dashboard.newPageUrl + "=" + item.key + "&post_title=" + item.name} />
107 {/* <a target='_blank' href={blockspare_dashboard.newPageUrl + "=" + item.key + "&post_title=" + item.name}>{__('Create block in new page', 'blockspare')}</a> */}
108 <Copycontent contentdata={item.content} />
109 </div>
110 }
111 </div>
112 </div>
113 </div>
114 </div>
115
116
117
118 )
119
120
121 })
122 }
123 </Masonry> : <div className="bs-loader-container">
124 <div className="bs-loader"></div>
125 </div>}
126 </div>
127 )
128
129 }
130
131 export default Sections