| 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 |