Skip to content

Commit 9bd74c4

Browse files
✏️ Update Pokemon brick, renderLink && NextLink
1 parent acad503 commit 9bd74c4

File tree

5 files changed

+49
-34
lines changed

5 files changed

+49
-34
lines changed
136 KB
Loading

react-bricks/NextLink.tsx

+4-2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import { types } from 'react-bricks/frontend'
44

55
const NextLink: types.RenderLocalLink = ({
66
href,
7+
target,
8+
rel,
79
className,
810
activeClassName,
911
isAdmin,
@@ -21,14 +23,14 @@ const NextLink: types.RenderLocalLink = ({
2123

2224
if (isAdmin) {
2325
return (
24-
<Link href={href} className={anchorClassName}>
26+
<Link href={href} target={target} rel={rel} className={anchorClassName}>
2527
{children}
2628
</Link>
2729
)
2830
}
2931

3032
return (
31-
<Link href={href} className={anchorClassName}>
33+
<Link href={href} target={target} rel={rel} className={anchorClassName}>
3234
{children}
3335
</Link>
3436
)

react-bricks/bricks/custom/MyHeroUnit.tsx

+6-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,12 @@ const MyHeroUnit: types.Brick<HeroUnitProps> = ({ padding }) => {
5959
</code>
6060
)}
6161
renderLink={(props) => (
62-
<a href={props.href} className="text-sky-500 hover:text-sky-600">
62+
<a
63+
href={props.href}
64+
target={props.target}
65+
rel={props.rel}
66+
className="text-sky-500 hover:text-sky-600 transition-colors"
67+
>
6368
{props.children}
6469
</a>
6570
)}

react-bricks/bricks/custom/Pokemon.tsx

+39-14
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import React from 'react'
22
import { types } from 'react-bricks/frontend'
33

44
interface PokemonProps {
5+
pokemonName: string
56
id: number
67
name: string
78
height: number
@@ -17,14 +18,19 @@ const Pokemon: types.Brick<PokemonProps> = ({
1718
imageUrl,
1819
}) => {
1920
if (!id || !name || !height || !weight || !imageUrl) {
20-
return (
21-
<div className="text-center text-red-500 underline text-xl">
22-
Pokemon not found!
23-
</div>
24-
)
21+
return null
2522
}
2623
return (
27-
<div className="container max-w-3xl mx-auto">
24+
<div className="my-6 pb-6 container max-w-3xl mx-auto border-2 border-slate-200">
25+
<div className="p-2 bg-slate-100 mb-6">
26+
<p className="text-sm text-slate-700 uppercase tracking-widest font-bold text-center mb-1">
27+
Test external data
28+
</p>
29+
<p className="text-center text-slate-600">
30+
You will not see this in the frontend, because it is an add-on feature
31+
on paid plans.
32+
</p>
33+
</div>
2834
<img src={imageUrl} className="mx-auto w-36 mb-4" />
2935

3036
<h1 className="text-5xl font-extrabold text-center mb-6">{name}</h1>
@@ -39,16 +45,35 @@ const Pokemon: types.Brick<PokemonProps> = ({
3945
Pokemon.schema = {
4046
name: 'pokemon',
4147
label: 'Pokemon',
42-
mapExternalDataToProps: (externalData, brickProps) => ({
43-
id: externalData.id,
44-
name: externalData.name,
45-
height: externalData.height,
46-
weight: externalData.weight,
47-
imageUrl: externalData.imageUrl,
48-
}),
48+
previewImageUrl: `/bricks-preview-images/pokemon.png`,
49+
getDefaultProps: () => ({}),
50+
getExternalData: (page, brickProps) =>
51+
fetch(`https://pokeapi.co/api/v2/pokemon/${brickProps.pokemonName}`)
52+
.then((response) => response.json())
53+
.then((data) => ({
54+
...data,
55+
imageUrl: `https://img.pokemondb.net/artwork/large/${data.name}.jpg`,
56+
}))
57+
.catch((error) => {
58+
return {
59+
id: 0,
60+
name: '',
61+
height: 0,
62+
weight: 0,
63+
imageUrl: '',
64+
}
65+
}),
4966

5067
// Sidebar Edit controls for props
51-
sideEditProps: [],
68+
sideEditProps: [
69+
{
70+
name: 'pokemonName',
71+
label: 'Pokemon Name',
72+
type: types.SideEditPropType.Text,
73+
helperText:
74+
'Enter a valid Pokemon name, like "pikachu" or "charizard" and save.',
75+
},
76+
],
5277
}
5378

5479
export default Pokemon

react-bricks/pageTypes.ts

-17
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ const pageTypes: types.IPageType[] = [
77
defaultLocked: false,
88
defaultStatus: types.PageStatus.Published,
99
getDefaultContent: () => [],
10-
excludedBlockTypes: ['pokemon'],
1110
},
1211
{
1312
name: 'blog',
@@ -26,22 +25,6 @@ const pageTypes: types.IPageType[] = [
2625
'blog-title',
2726
'newsletter-subscribe',
2827
],
29-
excludedBlockTypes: ['pokemon'],
30-
},
31-
{
32-
name: 'pokemon',
33-
pluralName: 'pokemon',
34-
getExternalData: (page) =>
35-
fetch(`https://pokeapi.co/api/v2/pokemon/${page.slug}`)
36-
.then((response) => response.json())
37-
.then((data) => ({
38-
...data,
39-
imageUrl: `https://img.pokemondb.net/artwork/large/${data.name}.jpg`,
40-
}))
41-
.catch((error) => {
42-
console.log(error)
43-
return {}
44-
}),
4528
},
4629
{
4730
name: 'layout',

0 commit comments

Comments
 (0)