diff --git a/src/pages/Home.tsx b/src/pages/Home.tsx index ac33451..65e17e8 100644 --- a/src/pages/Home.tsx +++ b/src/pages/Home.tsx @@ -7,18 +7,14 @@ const HomePage: React.FC = () => { const [searchTerm, setSearchTerm] = useState(''); useEffect(() => { - console.log('is this rendering'); const foundPoke = pokemonData.filter(pk => { return pk.name.toLowerCase().includes(searchTerm.toLowerCase()); }); searchTerm === '' ? setPokemon(pokemonData) : setPokemon(foundPoke); - }, []); - - // useEffect(()=>{},[]) + }, [searchTerm]); const handleChange = (event: ChangeEvent) => { - console.log(event.target.value); setSearchTerm(event.target.value); }; diff --git a/src/pages/SinglePokemon.tsx b/src/pages/SinglePokemon.tsx deleted file mode 100644 index 5b36735..0000000 --- a/src/pages/SinglePokemon.tsx +++ /dev/null @@ -1,155 +0,0 @@ -import React, { useState, useEffect } from 'react'; -import { useParams, Link } from 'react-router-dom'; -import { pokemonData } from '../data/pokemonData'; -import { setTypeColor } from '../services'; - -const SinglePokemonPage: React.FC = () => { - const [pokemon, setPokemon] = useState(); - const { pokemonName } = useParams<{ pokemonName: string }>(); - - useEffect(() => { - let foundPokemon = pokemonData.find( - pd => pd.name.toLowerCase() === pokemonName - ); - console.log(foundPokemon); - setPokemon(updateEvolution(foundPokemon)); - }, [pokemonName]); - - const updateEvolution = (poke: Pokemon | undefined) => { - // check for next_evolution && || prev_evolution - // loop through each of the evolution arrays - // loop through the pokemon data set - // find the pokemon in pokemonData that matches the evolution pokemon - // set the evolution.img = pokemon.img - // return our updatedPoke - - if (poke?.next_evolution) { - poke.next_evolution.map(ne => { - pokemonData.forEach(pd => { - if (pd.name === ne.name) { - ne.img = pd.img; - } - }); - return ne; - }); - } - - if (poke?.prev_evolution) { - poke.prev_evolution.map(pe => { - pokemonData.forEach(pd => { - if (pd.name === pe.name) { - pe.img = pd.img; - } - }); - return pe; - }); - } - - console.log(poke); - return poke; - }; - return ( -
- {pokemon ? ( -
-
-
-
-
-
- {pokemon.name} -
-
-
-
- {/* Card Title */} -

- {pokemon.name}{' '} - #{pokemon?.num} -

- {/* divider */} -
- {/* Pokemon Details */} -
-
-
Height
-
{pokemon.height}
-
Weight
-
{pokemon.weight}
-
-
-
Type
-
- {pokemon.type.map((t, i) => { - return ( - - {t} - - ); - })} -
- -
Weaknesses
-
- {pokemon.weaknesses.map((w, i) => { - return ( - - {w} - - ); - })} -
-
-
- {/* divider */} -
-
- {pokemon.prev_evolution?.map((pe, i) => { - return ( -
-
- Previous Evolution -
-
- - {pe.name} - -
- {pe.name} -
- ); - })} - {pokemon.next_evolution?.map((ne, i) => { - return ( -
-
Next Evolution
-
- - {ne.name} - -
- {ne.name} -
- ); - })} -
-
-
-
-
-
-
- ) : ( -

No Pokemon by that name was found!

- )} -
- ); -}; - -export default SinglePokemonPage;