Compare commits

..

No commits in common. "1d58f41b5f561be7af031c21fc328c285516b4e1" and "6acabeb91ac767a826831b82a8326b73c0d081d1" have entirely different histories.

4 changed files with 11 additions and 36 deletions

View File

@ -3,24 +3,13 @@ import './App.css';
import Header from 'components/Header'; import Header from 'components/Header';
import Pokedex from 'features/Pokedex'; import Pokedex from 'features/Pokedex';
import Filters from 'features/Filters'; import Filters from 'features/Filters';
import { useAppSelector } from 'app/hooks';
function App() { function App() {
const selectedRegion = useAppSelector(state => state.filter.selectedRegion);
const selectedType = useAppSelector(state => state.filter.selectedType);
const selectedSort = useAppSelector(state => state.filter.selectedSort);
const selectedSearchInput = useAppSelector(state => state.filter.searchInput);
return ( return (
<div className="App app_container"> <div className="App app_container">
<Header /> <Header />
<Filters /> <Filters />
<Pokedex <Pokedex />
selectedRegion={selectedRegion}
selectedType={selectedType}
selectedSort={selectedSort}
searchInput={selectedSearchInput}
/>
</div> </div>
); );
} }

View File

@ -1,12 +1,12 @@
import { import {
useGetRegionOptions, useGetRegionPokemons,
createRegionPokemonListOptionElements, createRegionPokemonListOptionElements,
} from './Filters'; } from './Filters';
describe('Filters', () => { describe('Filters', () => {
describe('test utility functions', () => { describe('test utility functions', () => {
test('createOptionElements works correctly', () => { test('createOptionElements works correctly', () => {
const { data } = useGetRegionOptions(); const { data } = useGetRegionPokemons();
const optionElements = createRegionPokemonListOptionElements(data); const optionElements = createRegionPokemonListOptionElements(data);
expect(optionElements[0].props.children).toBe('Kanto (1-151)'); expect(optionElements[0].props.children).toBe('Kanto (1-151)');
expect(optionElements[1].props.children).toBe('Johto (152-251)'); expect(optionElements[1].props.children).toBe('Johto (152-251)');

View File

@ -31,7 +31,7 @@ export const createRegionPokemonListOptionElements = (
}); });
}; };
export const useGetRegionOptions = () => { const useGetRegionOptions = () => {
const data: RegionPokemonRange[] = [ const data: RegionPokemonRange[] = [
{ region: 'kanto', startId: 1, endId: 151 }, { region: 'kanto', startId: 1, endId: 151 },
{ region: 'johto', startId: 152, endId: 251 }, { region: 'johto', startId: 152, endId: 251 },
@ -73,6 +73,7 @@ const Filters = () => {
dispatch(setSortOptions(fetchedSortOptions)); dispatch(setSortOptions(fetchedSortOptions));
dispatch(setSelectedRegion(fetchedRegionOptions[0].region)); dispatch(setSelectedRegion(fetchedRegionOptions[0].region));
dispatch(fetchPokemonsInTheRegion(fetchedRegionOptions[0].region));
dispatch(setSelectedSort(fetchedSortOptions[0].value)); dispatch(setSelectedSort(fetchedSortOptions[0].value));
}, []); }, []);

View File

@ -1,9 +1,8 @@
import React, { useEffect } from 'react'; import React from 'react';
import PokemonCard, { PokemonCardProps } from 'components/PokemonCard'; import PokemonCard, { PokemonCardProps } from 'components/PokemonCard';
import Loading from 'components/Loading'; import Loading from 'components/Loading';
import { useAppSelector, useAppDispatch } from 'app/hooks'; import { useAppSelector } from 'app/hooks';
import { fetchPokemonsInTheRegion } from './pokedexSlice';
export const filterPokemonCardsByType = ( export const filterPokemonCardsByType = (
pokemonList: PokemonCardProps[], pokemonList: PokemonCardProps[],
@ -40,20 +39,10 @@ export const searchPokemonCardsByName = (
); );
}; };
export interface PokedexProps { const Pokedex = () => {
selectedRegion: string; const selectedType = useAppSelector(state => state.filter.selectedType);
selectedType: string; const selectedSort = useAppSelector(state => state.filter.selectedSort);
selectedSort: string; const searchInput = useAppSelector(state => state.filter.searchInput);
searchInput: string;
}
const Pokedex = ({
selectedRegion,
selectedType,
selectedSort,
searchInput,
}: PokedexProps) => {
const dispatch = useAppDispatch();
const isLoadingPokemons = useAppSelector( const isLoadingPokemons = useAppSelector(
state => state.pokedex.isLoadingPokemons, state => state.pokedex.isLoadingPokemons,
@ -73,10 +62,6 @@ const Pokedex = ({
searchInput, searchInput,
); );
useEffect(() => {
dispatch(fetchPokemonsInTheRegion(selectedRegion));
}, [selectedRegion]);
return ( return (
<> <>
{isLoadingPokemons ? ( {isLoadingPokemons ? (