Skip to content

Commit 4457f6b

Browse files
feat: implement the compound pattern in pokemon style
1 parent 3991676 commit 4457f6b

File tree

15 files changed

+412
-560
lines changed

15 files changed

+412
-560
lines changed

src/course/02-lessons/01-Bronze/ConditionalRendering/exercise/exercise.tsx

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,15 @@ interface ITrainerProps {
99
// @ts-expect-error
1010
// eslint-disable-next-line @typescript-eslint/no-unused-vars
1111
export const PokemonTrainerStatus = (props: ITrainerProps) => {
12-
// 1a - 👨🏻💻 add a useState that has false as default. Name the variable [hasGymBadges, setHasGymBadges]
12+
// 1a - 💻 add a useState that has false as default. Name the variable [hasGymBadges, setHasGymBadges]
1313

14-
// 1b - 👨🏻💻 create me a onEarnBadge function which setHasGymBadges to be true
14+
// 1b - 💻 create me a onEarnBadge function which setHasGymBadges to be true
1515

16-
// 1c - 👨🏻💻 create me a onLoseBadges function which setHasGymBadges to be false
16+
// 1c - 💻 create me a onLoseBadges function which setHasGymBadges to be false
1717

18-
// 1d - 👨🏻💻 if hasGymBadges, return a button called "Reset Journey" with the onClick of onLoseBadges
19-
// 1e - 👨🏻💻 if hasGymBadges, return some text called "Welcome Gym Leader {props.trainerName}! 🏆"
18+
// 1d - 💻 if hasGymBadges, return a button called "Reset Journey" with the onClick of onLoseBadges
19+
// 1e - 💻 if hasGymBadges, return some text called "Welcome Gym Leader {props.trainerName}! 🏆"
2020

21-
// 1f - 👨🏻💻 add onClick function onEarnBadge to the button
21+
// 1f - 💻 add onClick function onEarnBadge to the button
2222
return <Button>🎯 Challenge Gym Leader</Button>;
23-
};
23+
};

src/course/02-lessons/01-Bronze/Hooks/exercise/exercise.tsx

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ const WILD_POKEMON = [
3434
{ id: 3, name: 'Pikachu', type: 'Electric', captureRate: 0.3 }
3535
];
3636

37-
// 1A 👨🏻💻 - We need to refactor this to be called usePokemonCapture
37+
// 1A 💻 - We need to refactor this to be called usePokemonCapture
3838
export const PokemonCaptureSystem = ({
3939
children
4040
}: IPokemonCaptureProps) => {
@@ -76,10 +76,10 @@ export const PokemonCaptureSystem = ({
7676
};
7777

7878
const restockPokeballs = (amount: number = 5) => {
79-
setPokeballs(prev => prev + amount);
79+
setPokeballs((prev) => prev + amount);
8080
};
8181

82-
// 1C 👨🏻💻 - Just return the object instead of children
82+
// 1C 💻 - Just return the object instead of children
8383
return children({
8484
wildPokemon,
8585
pokeballs,
@@ -96,7 +96,7 @@ export const PokemonCaptureSystem = ({
9696
// Let's make a component which uses the usePokemonCapture hook and takes an area prop
9797

9898
export const Exercise = () => {
99-
// 1E 👨🏻💻 - call the usePokemonCapture hook here
99+
// 1E 💻 - call the usePokemonCapture hook here
100100
return (
101101
<div className="p-6 bg-green-50 rounded-lg">
102102
<h2 className="text-2xl font-bold mb-4">
@@ -123,7 +123,10 @@ export const Exercise = () => {
123123
Captured: {capturedPokemon.length} Pokemon
124124
</p>
125125
</div>
126-
<Button onClick={() => restockPokeballs()} disabled={pokeballs >= 20}>
126+
<Button
127+
onClick={() => restockPokeballs()}
128+
disabled={pokeballs >= 20}
129+
>
127130
🛍️ Buy Pokeballs (+5)
128131
</Button>
129132
</div>

src/course/02-lessons/01-Bronze/PropsCombination/exercise/exercise.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import classnames from 'classnames';
22

33
/*
44
5-
1a👨🏻💻 group the following together:
5+
1a💻 group the following together:
66
77
* pokemon - pokemonName, pokemonType, pokemonHp, pokemonLevel
88
* attack - attackName, attackDamage, attackDescription
@@ -31,7 +31,7 @@ interface IPokemonCardProps {
3131
}
3232

3333
/*
34-
1b👨🏻💻 Update the props to match the new grouped types defined above.
34+
1b💻 Update the props to match the new grouped types defined above.
3535
*/
3636
export const Exercise = ({
3737
pokemonName,
@@ -56,7 +56,7 @@ export const Exercise = ({
5656
2a 🤔 Could we destructure the image to be [small, medium, large]?
5757
*/
5858
/*
59-
1c👨🏻💻 Update the props in the jsx to use the grouped structure
59+
1c💻 Update the props in the jsx to use the grouped structure
6060
*/
6161
return (
6262
<article
Lines changed: 73 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,47 @@
11
import classNames from 'classnames';
22

3-
// 👨🏻💻 1A - This component uses individual props for each map location. Can we refactor it to use slots instead?
3+
// 💻 1A - This component uses individual props for each map location. Can we refactor it to use slots instead?
44
interface IPokemonMap {
55
className?: string;
6-
6+
77
// North area props
88
showNorthArea?: boolean;
99
northAreaName?: string;
1010
northAreaIcon?: string;
1111
northAreaColor?: string;
12-
13-
// South area props
12+
13+
// South area props
1414
showSouthArea?: boolean;
1515
southAreaName?: string;
1616
southAreaIcon?: string;
1717
southAreaColor?: string;
18-
18+
1919
// East area props
2020
showEastArea?: boolean;
2121
eastAreaName?: string;
2222
eastAreaIcon?: string;
2323
eastAreaColor?: string;
24-
24+
2525
// West area props
2626
showWestArea?: boolean;
2727
westAreaName?: string;
2828
westAreaIcon?: string;
2929
westAreaColor?: string;
30-
30+
3131
// Center area props
3232
showCenterArea?: boolean;
3333
centerAreaName?: string;
3434
centerAreaIcon?: string;
3535
centerAreaColor?: string;
3636
}
3737

38-
const mapContainerClasses = 'grid grid-cols-3 grid-rows-3 gap-2 w-80 h-80 p-4 bg-green-100 rounded-lg border-2 border-green-300';
39-
const areaClasses = 'flex flex-col items-center justify-center p-3 rounded-lg border-2 text-sm font-bold text-white shadow-md';
38+
const mapContainerClasses =
39+
'grid grid-cols-3 grid-rows-3 gap-2 w-80 h-80 p-4 bg-green-100 rounded-lg border-2 border-green-300';
40+
const areaClasses =
41+
'flex flex-col items-center justify-center p-3 rounded-lg border-2 text-sm font-bold text-white shadow-md';
4042

41-
// 👨🏻💻 1B - Look at all these props and conditional logic! This is hard to maintain.
42-
// 👨🏻💻 1C - Refactor this to use northSlot, southSlot, eastSlot, westSlot, centerSlot instead
43+
// 💻 1B - Look at all these props and conditional logic! This is hard to maintain.
44+
// 💻 1C - Refactor this to use northSlot, southSlot, eastSlot, westSlot, centerSlot instead
4345
export const PokemonMap = ({
4446
className,
4547
showNorthArea,
@@ -67,100 +69,133 @@ export const PokemonMap = ({
6769
<div className={classNames(mapContainerClasses, className)}>
6870
{/* Empty top-left */}
6971
<div></div>
70-
72+
7173
{/* North area */}
72-
<div className={classNames(areaClasses, northAreaColor || 'bg-gray-400')}>
74+
<div
75+
className={classNames(
76+
areaClasses,
77+
northAreaColor || 'bg-gray-400'
78+
)}
79+
>
7380
{showNorthArea && (
7481
<>
7582
<span className="text-2xl mb-1">{northAreaIcon}</span>
76-
<span className="text-xs text-center">{northAreaName}</span>
83+
<span className="text-xs text-center">
84+
{northAreaName}
85+
</span>
7786
</>
7887
)}
7988
</div>
80-
89+
8190
{/* Empty top-right */}
8291
<div></div>
83-
92+
8493
{/* West area */}
85-
<div className={classNames(areaClasses, westAreaColor || 'bg-gray-400')}>
94+
<div
95+
className={classNames(
96+
areaClasses,
97+
westAreaColor || 'bg-gray-400'
98+
)}
99+
>
86100
{showWestArea && (
87101
<>
88102
<span className="text-2xl mb-1">{westAreaIcon}</span>
89-
<span className="text-xs text-center">{westAreaName}</span>
103+
<span className="text-xs text-center">
104+
{westAreaName}
105+
</span>
90106
</>
91107
)}
92108
</div>
93-
109+
94110
{/* Center area */}
95-
<div className={classNames(areaClasses, centerAreaColor || 'bg-gray-400')}>
111+
<div
112+
className={classNames(
113+
areaClasses,
114+
centerAreaColor || 'bg-gray-400'
115+
)}
116+
>
96117
{showCenterArea && (
97118
<>
98119
<span className="text-2xl mb-1">{centerAreaIcon}</span>
99-
<span className="text-xs text-center">{centerAreaName}</span>
120+
<span className="text-xs text-center">
121+
{centerAreaName}
122+
</span>
100123
</>
101124
)}
102125
</div>
103-
126+
104127
{/* East area */}
105-
<div className={classNames(areaClasses, eastAreaColor || 'bg-gray-400')}>
128+
<div
129+
className={classNames(
130+
areaClasses,
131+
eastAreaColor || 'bg-gray-400'
132+
)}
133+
>
106134
{showEastArea && (
107135
<>
108136
<span className="text-2xl mb-1">{eastAreaIcon}</span>
109-
<span className="text-xs text-center">{eastAreaName}</span>
137+
<span className="text-xs text-center">
138+
{eastAreaName}
139+
</span>
110140
</>
111141
)}
112142
</div>
113-
143+
114144
{/* Empty bottom-left */}
115145
<div></div>
116-
146+
117147
{/* South area */}
118-
<div className={classNames(areaClasses, southAreaColor || 'bg-gray-400')}>
148+
<div
149+
className={classNames(
150+
areaClasses,
151+
southAreaColor || 'bg-gray-400'
152+
)}
153+
>
119154
{showSouthArea && (
120155
<>
121156
<span className="text-2xl mb-1">{southAreaIcon}</span>
122-
<span className="text-xs text-center">{southAreaName}</span>
157+
<span className="text-xs text-center">
158+
{southAreaName}
159+
</span>
123160
</>
124161
)}
125162
</div>
126-
163+
127164
{/* Empty bottom-right */}
128165
<div></div>
129166
</div>
130167
);
131168
};
132169

133-
// 👨🏻💻 1D - Look at how verbose these prop combinations are!
134-
// 👨🏻💻 1E - Refactor these to use slots: northSlot={<LocationCard />}, centerSlot={<TownCard />}, etc.
170+
// 💻 1D - Look at how verbose these prop combinations are!
171+
// 💻 1E - Refactor these to use slots: northSlot={<LocationCard />}, centerSlot={<TownCard />}, etc.
135172
export const Exercise = () => (
136173
<div className="p-6 bg-blue-50 rounded-lg border-2 border-blue-200">
137-
<h2 className="text-2xl font-bold mb-4 text-blue-800">🗺️ Pokemon World Map</h2>
138-
174+
<h2 className="text-2xl font-bold mb-4 text-blue-800">
175+
🗺️ Pokemon World Map
176+
</h2>
177+
139178
<PokemonMap
140179
showNorthArea={true}
141180
northAreaName="Viridian Forest"
142181
northAreaIcon="🌲"
143182
northAreaColor="bg-green-600"
144-
145183
showSouthArea={true}
146184
southAreaName="Route 1"
147185
southAreaIcon="🛤️"
148186
southAreaColor="bg-yellow-600"
149-
150187
showEastArea={true}
151188
eastAreaName="Power Plant"
152189
eastAreaIcon="⚡"
153190
eastAreaColor="bg-yellow-500"
154-
155191
showWestArea={true}
156192
westAreaName="Mt. Silver"
157193
westAreaIcon="🏔️"
158194
westAreaColor="bg-gray-600"
159-
160195
showCenterArea={true}
161196
centerAreaName="Pallet Town"
162197
centerAreaIcon="🏠"
163198
centerAreaColor="bg-blue-600"
164199
/>
165200
</div>
166-
);
201+
);

0 commit comments

Comments
 (0)