11import { useState } from 'react' ;
2- import { Modal } from './components/modal' ;
2+ import { BattleOverlay } from './components/modal' ;
33import { Button } from '@shared/components/Button/Button.component' ;
44
5- // 👨🏻 💻 1A - have a look at the current implementation of the modal and then go to components/modal.tsx
5+ // 👨🏻💻 1A - have a look at the current implementation of the battle overlay and then go to components/modal.tsx
66
77export const Exercise = ( ) => {
8- const [ isVisible , setIsVisible ] = useState ( false ) ;
9- const [ isComplete , setIsComplete ] = useState ( false ) ;
8+ const [ isBattleActive , setIsBattleActive ] = useState ( false ) ;
9+ const [ battleResult , setBattleResult ] = useState < 'won' | 'fled' | null > ( null ) ;
1010
11- const onClose = ( ) => {
12- setIsVisible ( false ) ;
11+ const onCloseBattle = ( ) => {
12+ setIsBattleActive ( false ) ;
1313 } ;
1414
15- const onOpen = ( ) => {
16- setIsVisible ( true ) ;
15+ const onStartBattle = ( ) => {
16+ setIsBattleActive ( true ) ;
17+ setBattleResult ( null ) ;
1718 } ;
1819
19- const onCheckout = ( ) => {
20- setIsComplete ( true ) ;
20+ const onBattleAction = ( action : 'attack' | 'run' ) => {
21+ if ( action === 'attack' ) {
22+ setBattleResult ( 'won' ) ;
23+ } else {
24+ setBattleResult ( 'fled' ) ;
25+ }
26+ setTimeout ( ( ) => {
27+ setIsBattleActive ( false ) ;
28+ setBattleResult ( null ) ;
29+ } , 2000 ) ;
2130 } ;
2231
2332 return (
24- // 🧪 We have z-index 10 on the section and then z-9998 on a div that's purposely there. Our Modal has a z-20 which means:
33+ // 🧪 We have z-index 10 on the section and then z-9998 on a div that's purposely there. Our BattleOverlay has a z-20 which means:
2534 // section z-10
26- // modal z-20 (but this means z-20 within the z-10) think of it as a sub layer.
27- // the bug is 9998 and a css hack for the pay now is 9999
28- < section className = "z-10 relative h-screen" >
29- < div className = "z-[9998] absolute top-0 left-0 right-0 bottom-0" />
30- { isComplete && (
31- < >
32- < h1 className = "text-xl font-semibold" >
33- Payment Successful
34- </ h1 >
35- < p className = "text-md mb-2" > Well done you did it!</ p >
36- </ >
37- ) }
35+ // battle overlay z-20 (but this means z-20 within the z-10) think of it as a sub layer.
36+ // the bug is 9998 and a css hack for the battle buttons is 9999
37+ < section className = "z-10 relative h-screen bg-green-100 p-6" >
38+ < div className = "z-[9998] absolute top-0 left-0 right-0 bottom-0 bg-black/10" />
39+
40+ < div className = "relative z-[9999]" >
41+ < h1 className = "text-2xl font-bold mb-4 text-green-800" > 🌿 Pokemon World</ h1 >
3842
39- { ! isComplete && (
40- < >
41- < h1 className = "text-xl font-semibold" > Payment Page</ h1 >
43+ < div className = "grid grid-cols-3 gap-4 mb-6" >
44+ < div className = "bg-green-200 p-4 rounded-lg text-center" >
45+ < div className = "text-4xl mb-2" > 🌲</ div >
46+ < p className = "text-sm" > Tall Grass</ p >
47+ </ div >
48+ < div className = "bg-blue-200 p-4 rounded-lg text-center" >
49+ < div className = "text-4xl mb-2" > 🏠</ div >
50+ < p className = "text-sm" > Pokemon Center</ p >
51+ </ div >
52+ < div className = "bg-yellow-200 p-4 rounded-lg text-center" >
53+ < div className = "text-4xl mb-2" > 🏪</ div >
54+ < p className = "text-sm" > Poke Mart</ p >
55+ </ div >
56+ </ div >
4257
43- < p className = "text-md mb-2" >
44- Please see your selected options from the previous steps
45- before continuing.
58+ < div className = "bg-white p-6 rounded-lg border-2 border-green-300 mb-6" >
59+ < h2 className = "text-lg font-semibold mb-4" > 🎒 Trainer Actions</ h2 >
60+ < p className = "text-md mb-4" >
61+ You're walking through the tall grass. Wild Pokemon might appear!
4662 </ p >
63+
64+ < div className = "text-center" >
65+ < Button
66+ onClick = { onStartBattle }
67+ className = "bg-red-500 hover:bg-red-600"
68+ disabled = { isBattleActive }
69+ >
70+ 🔍 Search for Pokemon
71+ </ Button >
72+ </ div >
73+ </ div >
4774
48- < section className = "my-6" >
49- < h2 className = "text-lg font-semibold mb-2" >
50- Delivery Details
51- </ h2 >
52- < address className = "border border-grey-300 rounded-md p-3 mb-2 block" >
53- < p > 12 john doe street, Manchester, M12 3RT</ p >
54- </ address >
55- </ section >
75+ < div className = "bg-gray-100 p-4 rounded-lg" >
76+ < h3 className = "font-semibold mb-2" > 🎮 Game Status</ h3 >
77+ < p className = "text-sm text-gray-600" >
78+ { isBattleActive ? 'Battle in progress...' : 'Exploring the world' }
79+ </ p >
80+ { battleResult && (
81+ < p className = "text-sm font-semibold mt-2" >
82+ { battleResult === 'won' ? '🎉 Victory!' : '💨 Pokemon fled!' }
83+ </ p >
84+ ) }
85+ </ div >
86+ </ div >
5687
57- < section className = "z-[9999] relative" >
58- < h2 className = "text-lg font-semibold mb-2" >
59- Make Payment
60- </ h2 >
61- < Button onClick = { onOpen } > Pay now</ Button >
62- </ section >
63- </ >
64- ) }
65- { isVisible && ! isComplete && (
66- < Modal
67- id = "modal"
68- onClose = { onClose }
69- isVisible = { isVisible }
70- title = "Some fancy payment form..."
71- >
72- < Button onClick = { onCheckout } > Pay now</ Button >
73- </ Modal >
88+ { isBattleActive && (
89+ < BattleOverlay
90+ id = "battle-overlay"
91+ onClose = { onCloseBattle }
92+ isVisible = { isBattleActive }
93+ wildPokemon = { {
94+ name : 'Pidgey' ,
95+ level : 5 ,
96+ sprite : 'https://raw.githubusercontent.com/PokeAPI/sprites/master/sprites/pokemon/16.png'
97+ } }
98+ onBattleAction = { onBattleAction }
99+ battleResult = { battleResult }
100+ />
74101 ) }
75102 </ section >
76103 ) ;
77- } ;
104+ } ;
0 commit comments