Skip to content

Commit

Permalink
filtered pokemons
Browse files Browse the repository at this point in the history
  • Loading branch information
pluvio72 committed Aug 6, 2022
1 parent 40c1264 commit 496611f
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 5 deletions.
16 changes: 16 additions & 0 deletions src/index.scss
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
// Bootstrap customization to make it
// more pokemon-esc looking

.form-control, .form-select{
border: 3px solid black!important;
font-weight: 600!important;
}
.form-control{
background-color:black!important;
color: white!important;
}
.form-control:focus, .form-control:active,
.form-select:focus, .form-select:active{
box-shadow: 0px 0px 0px 4px #d6d6d6!important;
}

@import "~bootstrap/scss/bootstrap";

body {
Expand Down
15 changes: 11 additions & 4 deletions src/views/Pokedex/pokedex.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ import "./pokedex.scss";
function Pokedex() {
const { addPokemonToList, getAllPokemon } = useContext(Pokemon);

const [filter, setFilter] = useState('');
const [pokemon, setPokemon] = useState({});
const [loading, setLoading] = useState(true);

// cache first 20 pokemon for index page
useEffect(() => {
Expand All @@ -45,9 +45,15 @@ function Pokedex() {
} else setPokemon(getAllPokemon());
}, []);

const onChangeFilter = (event) => {
// all data in lower case for case insensitive filtering
setFilter(event.target.value.toLowerCase());
}

const onSelectGeneration = (event) => {
const newGenerationValue = event.target.value;


setPokemon({});
getPokemonByGeneration(newGenerationValue).then(async (data) => {
const allFetchedPokemon = getAllPokemon();
const allFetchedPokemonNames = Object.keys(allFetchedPokemon);
Expand Down Expand Up @@ -95,7 +101,8 @@ function Pokedex() {
<FormControl
type="text"
placeholder="Search by pokemon name..."
/>
onChange={onChangeFilter}
/>
</div>
<div className="flex-shrink-1">
<FormSelect onChange={onSelectGeneration}>
Expand All @@ -113,7 +120,7 @@ function Pokedex() {
</div>
{Object.keys(pokemon).length > 0 ? (
<Row className="gx-2 gy-2">
{Object.keys(pokemon).map((_name) => (
{Object.keys(pokemon).filter(e => e.toLowerCase().indexOf(filter) > -1).map((_name) => (
<Col className="col-3" key={_name}>
<div className="pokemon-card py-2 px-3">
<span className="lead">{formatName(_name)}</span>
Expand Down
2 changes: 1 addition & 1 deletion src/views/Pokedex/pokedex.scss
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
.pokemon-card{
border: 2px solid rgb(90,90,90);
border: 3px solid rgb(0, 0, 0);
background-color: rgb(240,241,242);
border-radius: .5rem;
display: flex;
Expand Down

0 comments on commit 496611f

Please sign in to comment.