| 1 |
import React, { useState } from 'react' |
| 2 |
import Switch from '../components/Switch' |
| 3 |
import { blocksData } from '../data/blocksData' |
| 4 |
import { playIcon } from '../data/icons' |
| 5 |
const { __ } = wp.i18n |
| 6 |
|
| 7 |
|
| 8 |
const Blocks = () => { |
| 9 |
// const [blocks, setBlocks] = useState(blocksData.blocks); |
| 10 |
|
| 11 |
// // Determine if all blocks are currently enabled |
| 12 |
// const allBlocksEnabled = blocks.every((block) => block.isEnabled === true); |
| 13 |
|
| 14 |
// // Determine if all blocks are currently enabled |
| 15 |
// const allBlocksDisable = blocks.every((block) => block.isEnabled === false); |
| 16 |
|
| 17 |
// // Determine if all blocks in each category are currently enabled |
| 18 |
// const categoryEnabledStatus = {}; |
| 19 |
// blocksData.categories.forEach((category) => { |
| 20 |
// const categoryBlocks = blocks.filter( |
| 21 |
// (block) => block.categoryId === category.slug |
| 22 |
// ); |
| 23 |
// categoryEnabledStatus[category.slug] = categoryBlocks.every( |
| 24 |
// (block) => block.isEnabled === true |
| 25 |
// ); |
| 26 |
// }); |
| 27 |
|
| 28 |
// // Determine if all blocks in each category are currently disable |
| 29 |
// const categoryDisableStatus = {}; |
| 30 |
// blocksData.categories.forEach((category) => { |
| 31 |
// const categoryBlocks = blocks.filter( |
| 32 |
// (block) => block.categoryId === category.slug |
| 33 |
// ); |
| 34 |
// categoryDisableStatus[category.slug] = categoryBlocks.every( |
| 35 |
// (block) => block.isEnabled === false |
| 36 |
// ); |
| 37 |
// }); |
| 38 |
|
| 39 |
// // Handler for toggling the global enable/disable state of all blocks |
| 40 |
// const handleGlobalToggle = (event) => { |
| 41 |
// const isEnabled = event.target.value === "enable"; |
| 42 |
// const updatedBlocks = blocks.map((block) => { |
| 43 |
// return { ...block, isEnabled }; |
| 44 |
// }); |
| 45 |
// setBlocks(updatedBlocks); |
| 46 |
// }; |
| 47 |
|
| 48 |
// // Handler for toggling the enable/disable state of all blocks in a category |
| 49 |
// const handleCategoryToggle = (event, categoryId) => { |
| 50 |
// const isEnabled = event.target.value === "enable"; |
| 51 |
// const updatedBlocks = blocks.map((block) => { |
| 52 |
// if (block.categoryId === categoryId) { |
| 53 |
// return { ...block, isEnabled }; |
| 54 |
// } else { |
| 55 |
// return block; |
| 56 |
// } |
| 57 |
// }); |
| 58 |
// setBlocks(updatedBlocks); |
| 59 |
// }; |
| 60 |
|
| 61 |
// // Handler for toggling the enable/disable state of a single block |
| 62 |
// const handleBlockToggle = (event, blockId) => { |
| 63 |
// const isEnabled = event.target.checked; |
| 64 |
// const updatedBlocks = blocks.map((block) => { |
| 65 |
// if (block.slug === blockId) { |
| 66 |
// return { ...block, isEnabled }; |
| 67 |
// } else { |
| 68 |
// return block; |
| 69 |
// } |
| 70 |
// }); |
| 71 |
// setBlocks(updatedBlocks); |
| 72 |
// }; |
| 73 |
|
| 74 |
return ( |
| 75 |
<div className="block-list"> |
| 76 |
<div className="blocklist-page"> |
| 77 |
<div className="blocklist-container"> |
| 78 |
{/* <div className="blocklist-header"> |
| 79 |
<h1>Global Control</h1> |
| 80 |
<div className="block-enable-disable-all"> |
| 81 |
<button className={`disable-all ${allBlocksDisable ? "active" : ""}`} onClick={handleGlobalToggle} value="disable" >Disable All</button> |
| 82 |
<button className={`enable-all ${allBlocksEnabled ? "active" : ""}`} onClick={handleGlobalToggle} value="enable" >Enable All</button> |
| 83 |
</div> |
| 84 |
</div> */} |
| 85 |
<div className="blocklist-body"> |
| 86 |
<div className="wrapper"> |
| 87 |
{ |
| 88 |
blocksData.categories.map((category) => ( |
| 89 |
<div className="block-category" kay={category.slug}> |
| 90 |
<div className="block-category-info"> |
| 91 |
<h2 className="block-category-heading">{__(category.name, 'blockspare')}</h2> |
| 92 |
{/* <div className="block-enable-disable-all"> |
| 93 |
<button className={`disable-all ${categoryDisableStatus[category.slug] ? "active" : ""}`} onClick={(event) => handleCategoryToggle(event, category.slug)} value="disable" >Disable All</button> |
| 94 |
<button className={`enable-all ${categoryEnabledStatus[category.slug] ? "active" : ""}`} onClick={(event) => handleCategoryToggle(event, category.slug)} value="enable" >Enable All</button> |
| 95 |
</div> */} |
| 96 |
</div> |
| 97 |
<div className="blockspare_block_cards"> |
| 98 |
{blocksData.blocks |
| 99 |
.filter((block) => block.categoryId === category.slug) |
| 100 |
.map((block) => ( |
| 101 |
<div class={`blockspare_block_card ${block.isEnabled ? "active" : ""}`}> |
| 102 |
<div className="blockspare_block_card__icon"> |
| 103 |
{block.icon} |
| 104 |
</div> |
| 105 |
<div class="blockspare_block_card__info" > |
| 106 |
<div class="blockspare_block_card__header"> |
| 107 |
<h3 class="blockspare_block_card__title">{__(block.name, 'blockspare')}</h3> |
| 108 |
</div> |
| 109 |
<div class="blockspare_block_card__footer"> |
| 110 |
<a href={block.demo_link} target="_blank" class="blockspare_block_card__link">{__('Live Demo', 'blockspare')}</a> |
| 111 |
<a href={block.video_link} target="_blank" class="blockspare_block_card__video_link"> |
| 112 |
{playIcon} |
| 113 |
</a> |
| 114 |
{/* <Switch data={block} handleChange={handleBlockToggle} /> */} |
| 115 |
</div> |
| 116 |
</div> |
| 117 |
</div> |
| 118 |
))} |
| 119 |
</div> |
| 120 |
</div> |
| 121 |
)) |
| 122 |
} |
| 123 |
</div> |
| 124 |
</div> |
| 125 |
</div> |
| 126 |
</div> |
| 127 |
</div> |
| 128 |
) |
| 129 |
} |
| 130 |
|
| 131 |
export default Blocks |
| 132 |
|
| 133 |
|