PluginProbe
BlockSpare – Gutenberg Blocks for News, Magazine, Blog & Business Websites / 2.7.1
BlockSpare – Gutenberg Blocks for News, Magazine, Blog & Business Websites v2.7.1
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 2.7.1, at admin/pages/demo/sections.js

85 lines 3.0 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 { apiFetch } = wp;
3 import Masonry from 'react-masonry-component';
4 const Sections = () => {
5 const [isLoading, setISLoading] = useState(false)
6 const [sections, setSections] = useState([]);
7 useEffect(() => {
8 wp.apiFetch({
9 method: 'GET',
10 path: '/blockspare/v1/layouts/all?filter=allowed',
11 }).then(async (components) => {
12 const sections = [];
13 Object.values(components).forEach(function (item) {
14
15 if ('section' === item.type) {
16 sections.push(item);
17 }
18 })
19 setISLoading(true)
20 setSections(sections)
21
22 })
23
24 }, [])
25
26 const masonryOptions = {
27 transitionDuration: 0,
28 percentPosition: true,
29 };
30
31 return (
32
33 <div className='bs-pages-demo-wrapper'>
34 {isLoading ? <Masonry
35 elementType={'div'}
36 className={`bs-templates-container`}
37 options={masonryOptions}
38 disableImagesLoaded={false}
39 updateOnEachImageLoad={false}
40 >
41 {sections &&
42 sections.map((item, i) => {
43 const nameInLowerCase = item.name.toLowerCase();
44 const imageName = nameInLowerCase.replace(/\s+/g, '-');
45 const folderName = item.imagePath
46 return (
47
48 <div className='bs-layout-pages-inside'>
49 {
50 item.content === 'https://www.blockspare.com/' &&
51 <span className="bs-pro-badge">pro </span>
52 }
53 <div className='bs-layout-pages-item'>
54 <div className='LazyLoad is-visible'>
55 <a href={item.blockLink} target='_blank' >
56 <img
57 src={blockspare_dashboard.imagePath + folderName + "/" + imageName + ".jpg"}
58 alt={item.name}
59 />
60 </a>
61 </div>
62 <div className='bs-layout-pages-info'>
63 <div className='bs-layout-design-title'>
64 <a href={item.blockLink} target='_blank' >{item.name}</a>
65 </div>
66 </div>
67 </div>
68 </div>
69
70
71
72 )
73
74
75 })
76 }
77 </Masonry> : <div className="bs-loader-container">
78 <div className="bs-loader"></div>
79 </div>}
80 </div>
81 )
82
83 }
84
85 export default Sections