Skip to content
This repository was archived by the owner on Feb 27, 2024. It is now read-only.

Commit e2c06a5

Browse files
committed
PR review refactors
1 parent 5ab0aed commit e2c06a5

File tree

1 file changed

+28
-21
lines changed

1 file changed

+28
-21
lines changed

functions/displayBlock.js

Lines changed: 28 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,57 +2,64 @@ import * as Blocks from '@/components/blocks'
22
import PropTypes from 'prop-types'
33

44
/**
5-
* Decide which block to display.
5+
* Decide which block component to display.
66
*
7-
* @author WebDevStudios
8-
* @param {object} block The block data.
7+
* @param {object} block The block data.
8+
* @param {number} index A unique key required by React.
9+
* @param {object} siteSettings Global settings.
10+
* @return {node} A block-based component
911
*/
1012
export default function displayBlock(block, index, siteSettings) {
13+
const {attributes, name} = block
14+
const {algolia} = siteSettings
15+
1116
// prettier-ignore
12-
switch (block.name) {
17+
switch (name) {
1318
case 'acf/accordions':
14-
return <Blocks.BlockAccordions props={block.attributes} key={index} />
19+
return <Blocks.BlockAccordions props={attributes} key={index} />
1520
case 'acf/algolia':
1621
return (
1722
<Blocks.BlockAlgolia
18-
props={block.attributes}
23+
props={attributes}
1924
key={index}
2025
indexName={
21-
siteSettings?.algolia?.indexName
22-
? siteSettings.algolia.indexName
26+
algolia?.indexName
27+
? algolia.indexName
2328
: ''
2429
}
2530
/>
2631
)
2732
case 'acf/netflix':
2833
return (
29-
<Blocks.BlockNetflixCarousel props={block.attributes} key={index} />
34+
<Blocks.BlockNetflixCarousel props={attributes} key={index} />
3035
)
3136
case 'core/block-quote':
32-
return <Blocks.BlockBlockquote props={block.attributes} key={index} />
37+
return <Blocks.BlockBlockquote props={attributes} key={index} />
3338
case 'core/embed':
34-
return <Blocks.BlockVideoEmbed props={block.attributes} key={index} />
39+
return <Blocks.BlockVideoEmbed props={attributes} key={index} />
3540
case 'core/heading':
36-
return <Blocks.BlockHeadings props={block.attributes} key={index} />
41+
return <Blocks.BlockHeadings props={attributes} key={index} />
3742
case 'core/image':
38-
return <Blocks.BlockImage props={block.attributes} key={index} />
43+
return <Blocks.BlockImage props={attributes} key={index} />
3944
case 'core/image-gallery':
40-
return <Blocks.BlockImageGallery props={block.attributes} key={index} />
45+
return <Blocks.BlockImageGallery props={attributes} key={index} />
4146
case 'core/list':
42-
return <Blocks.BlockList props={block.attributes} key={index} />
47+
return <Blocks.BlockList props={attributes} key={index} />
4348
case 'core/paragraph':
44-
return <Blocks.BlockParagraph props={block.attributes} key={index} />
49+
return <Blocks.BlockParagraph props={attributes} key={index} />
4550
case 'core/separator':
46-
return <Blocks.BlockSeparator props={block.attributes} key={index} />
51+
return <Blocks.BlockSeparator props={attributes} key={index} />
4752
case 'core/shortcode':
48-
return <Blocks.BlockShortcode props={block.attributes} key={index} />
53+
return <Blocks.BlockShortcode props={attributes} key={index} />
4954
case 'core/spacer':
50-
return <Blocks.BlockSpacer props={block.attributes} key={index} />
55+
return <Blocks.BlockSpacer props={attributes} key={index} />
5156
default:
52-
return <pre key={index}>{JSON.stringify(block.attributes, null, 2)}</pre>
57+
return <pre key={index}>{JSON.stringify(attributes, null, 2)}</pre>
5358
}
5459
}
5560

5661
displayBlock.propTypes = {
57-
block: PropTypes.object.isRequired
62+
block: PropTypes.object.isRequired,
63+
index: PropTypes.number.isRequired,
64+
siteSettings: PropTypes.object.isRequired
5865
}

0 commit comments

Comments
 (0)