1
- import { useState , useReducer , useEffect } from "react" ;
1
+ import { useState , useReducer } from "react" ;
2
2
import GameCard from "./components/GameCard" ;
3
3
import "./App.css" ;
4
4
import { Navbar , Nav , NavDropdown , Row , Col , Container } from "react-bootstrap" ;
5
- import axios from "./axios" ;
6
- import { propTypes } from "react-bootstrap/esm/Image" ;
7
5
8
6
const defaultPokedex = [
9
7
{
@@ -68,14 +66,13 @@ const defaultPokedex = [
68
66
} ,
69
67
] ;
70
68
69
+ // BUGS: When high score is recorded images stop changing.
71
70
function App ( ) {
72
71
const [ , forceUpdate ] = useReducer ( x => x + 1 , 0 ) ;
73
72
const [ score , setScore ] = useState ( 0 ) ;
74
73
const [ highScore , setHS ] = useState ( 0 ) ;
75
74
const [ pokedex , setPokedex ] = useState ( defaultPokedex ) ;
76
- const [ imageCache , setImageCache ] = useState ( { } ) ;
77
75
const [ pokemonToDisplay , setPokemonToDisply ] = useState ( defaultPokedex ) ;
78
- const [ isLoading , setLoading ] = useState ( null ) ;
79
76
80
77
function isHighScore ( newScore ) {
81
78
if ( newScore > highScore ) setHS ( newScore ) ;
@@ -98,25 +95,6 @@ function App() {
98
95
setPokemonToDisply ( array ) ;
99
96
forceUpdate ( ) ;
100
97
}
101
- useEffect ( ( ) => {
102
- async function cacheImages ( ) {
103
- try {
104
- let cacheImages = { } ;
105
- pokedex . map ( async ( pokemon ) => {
106
- const response = await axios . get ( pokemon . name ) ;
107
- const img_url = response . data . sprites . other [ "official-artwork" ] ;
108
- cacheImages [ pokemon . name ] = img_url . front_default ;
109
- console . log ( img_url . front_default ) ;
110
- console . log ( cacheImages [ pokemon . name ] ) ;
111
- } ) ;
112
- setImageCache ( cacheImages ) ;
113
- } catch ( error ) {
114
- console . error ( error ) ;
115
- }
116
- }
117
- cacheImages ( ) ;
118
- setLoading ( false ) ;
119
- } , [ pokedex ] )
120
98
121
99
const handleClick = ( pokemonID ) => {
122
100
let newState = ( pokedex . map ( pokemon => {
@@ -138,21 +116,6 @@ function App() {
138
116
< Navbar . Brand href = "#home" > Pokemon Memorization</ Navbar . Brand >
139
117
< Navbar . Toggle aria-controls = "basic-navbar-nav" />
140
118
< Navbar . Collapse id = "basic-navbar-nav" >
141
- { /* <Nav className="me-auto">
142
- <Nav.Link href="#home">Home</Nav.Link>
143
- <Nav.Link href="#link">Link</Nav.Link>
144
- <NavDropdown title="Dropdown" id="basic-nav-dropdown">
145
- <NavDropdown.Item href="#action/3.1">Action</NavDropdown.Item>
146
- <NavDropdown.Item href="#action/3.2">
147
- Another action
148
- </NavDropdown.Item>
149
- <NavDropdown.Item href="#action/3.3">Something</NavDropdown.Item>
150
- <NavDropdown.Divider />
151
- <NavDropdown.Item href="#action/3.4">
152
- Separated link
153
- </NavDropdown.Item>
154
- </NavDropdown>
155
- </Nav> */ }
156
119
</ Navbar . Collapse >
157
120
< Navbar . Collapse className = "justify-content-end" >
158
121
< Col >
@@ -178,9 +141,7 @@ function App() {
178
141
key = { index }
179
142
name = { pokemon . name }
180
143
handleClick = { handleClick }
181
- images = { imageCache }
182
144
id = { pokemon . id }
183
- isLoading = { isLoading }
184
145
/>
185
146
) ) }
186
147
</ Row >
0 commit comments