|
| 1 | +import * as Blocks from '@/components/blocks' |
| 2 | +import PropTypes from 'prop-types' |
| 3 | + |
| 4 | +/** |
| 5 | + * Decide which block to display. |
| 6 | + * |
| 7 | + * @author WebDevStudios |
| 8 | + * @param {object} block The block data. |
| 9 | + */ |
| 10 | +export default function displayBlock(block, index, siteSettings) { |
| 11 | + // prettier-ignore |
| 12 | + switch (block.name) { |
| 13 | + case 'acf/accordions': |
| 14 | + return <Blocks.BlockAccordions props={block.attributes} key={index} /> |
| 15 | + case 'acf/algolia': |
| 16 | + return ( |
| 17 | + <Blocks.BlockAlgolia |
| 18 | + props={block.attributes} |
| 19 | + key={index} |
| 20 | + indexName={ |
| 21 | + siteSettings?.algolia?.indexName |
| 22 | + ? siteSettings.algolia.indexName |
| 23 | + : '' |
| 24 | + } |
| 25 | + /> |
| 26 | + ) |
| 27 | + case 'acf/netflix': |
| 28 | + return ( |
| 29 | + <Blocks.BlockNetflixCarousel props={block.attributes} key={index} /> |
| 30 | + ) |
| 31 | + case 'core/block-quote': |
| 32 | + return <Blocks.BlockBlockquote props={block.attributes} key={index} /> |
| 33 | + case 'core/embed': |
| 34 | + return <Blocks.BlockVideoEmbed props={block.attributes} key={index} /> |
| 35 | + case 'core/heading': |
| 36 | + return <Blocks.BlockHeadings props={block.attributes} key={index} /> |
| 37 | + case 'core/image': |
| 38 | + return <Blocks.BlockImage props={block.attributes} key={index} /> |
| 39 | + case 'core/image-gallery': |
| 40 | + return <Blocks.BlockImageGallery props={block.attributes} key={index} /> |
| 41 | + case 'core/list': |
| 42 | + return <Blocks.BlockList props={block.attributes} key={index} /> |
| 43 | + case 'core/paragraph': |
| 44 | + return <Blocks.BlockParagraph props={block.attributes} key={index} /> |
| 45 | + case 'core/separator': |
| 46 | + return <Blocks.BlockSeparator props={block.attributes} key={index} /> |
| 47 | + case 'core/shortcode': |
| 48 | + return <Blocks.BlockShortcode props={block.attributes} key={index} /> |
| 49 | + case 'core/spacer': |
| 50 | + return <Blocks.BlockSpacer props={block.attributes} key={index} /> |
| 51 | + default: |
| 52 | + return <pre key={index}>{JSON.stringify(block.attributes, null, 2)}</pre> |
| 53 | + } |
| 54 | +} |
| 55 | + |
| 56 | +displayBlock.propTypes = { |
| 57 | + block: PropTypes.object.isRequired |
| 58 | +} |
0 commit comments