diff --git a/src/App.tsx b/src/App.tsx index cbd380d..467c96a 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -8,20 +8,12 @@ import { useAppSelector } from 'app/hooks'; 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 (
- +
); diff --git a/src/features/Filters/filterSlice.ts b/src/features/Filters/filterSlice.ts index 2fa9528..39f57ce 100644 --- a/src/features/Filters/filterSlice.ts +++ b/src/features/Filters/filterSlice.ts @@ -4,12 +4,12 @@ import { PayloadAction, Slice, } from '@reduxjs/toolkit'; -import { FilterState } from './types/slice'; +import { FilterStateProps } from './types/slice'; import { RegionPokemonRange } from './types/slice'; import { pokeRestApi } from 'app/services/pokeRestApi'; import { fetchPokemonsInTheRegion } from 'features/Pokedex/pokedexSlice'; -const initialState: FilterState = { +export const initialState: FilterStateProps = { regionOptions: [], typeOptions: [], sortOptions: [], @@ -46,7 +46,7 @@ export const initializeFilterSlice = createAsyncThunk( }, ); -export const filterSlice: Slice = createSlice({ +export const filterSlice: Slice = createSlice({ name: 'filter', initialState, reducers: { diff --git a/src/features/Filters/types/slice.ts b/src/features/Filters/types/slice.ts index 0d5a602..922f3a4 100644 --- a/src/features/Filters/types/slice.ts +++ b/src/features/Filters/types/slice.ts @@ -1,4 +1,4 @@ -export type FilterState = { +export type FilterStateProps = { regionOptions: RegionPokemonRange[]; typeOptions: string[]; sortOptions: { name: string; value: string }[]; diff --git a/src/features/Pokedex/Pokedex.stories.tsx b/src/features/Pokedex/Pokedex.stories.tsx index c543a78..64697e7 100644 --- a/src/features/Pokedex/Pokedex.stories.tsx +++ b/src/features/Pokedex/Pokedex.stories.tsx @@ -3,8 +3,10 @@ import { configureStore, createSlice } from '@reduxjs/toolkit'; import type { Meta } from '@storybook/react'; import Pokedex from './Pokedex'; -import { initialState } from './pokedexSlice'; +import { initialState as initialPokedexState } from './pokedexSlice'; +import { initialState as initialFilterState } from '../Filters/filterSlice'; import { PokedexStateProps } from './types/slice'; +import { FilterStateProps } from 'features/Filters/types/slice'; const MockedState = { // Copied from Redux DevTools from browser @@ -62,30 +64,55 @@ const MockedState = { }, ], }, + filter: { + regionOptions: [], + typeOptions: [], + sortOptions: [], + selectedRegion: 'kanto', + selectedType: 'All Types', + selectedSort: 'id', + searchInput: '', + }, }; interface MockStoreProps { pokedexState: PokedexStateProps; + filterState: FilterStateProps; children: React.ReactNode; } // Create a mock store -const mockSlice = (pokedexState: PokedexStateProps) => { +const mockPokedexSlice = (pokedexState: PokedexStateProps) => { return createSlice({ name: 'pokedex', initialState: pokedexState, reducers: {}, }); }; -const mockStore = (pokedexState: PokedexStateProps) => { +const mockFilterSlice = (filterState: FilterStateProps) => { + return createSlice({ + name: 'filter', + initialState: filterState, + reducers: {}, + }); +}; +const mockStore = ( + pokedexState: PokedexStateProps, + filterState: FilterStateProps, +) => { return configureStore({ reducer: { - pokedex: mockSlice(pokedexState).reducer, + filter: mockFilterSlice(filterState).reducer, + pokedex: mockPokedexSlice(pokedexState).reducer, }, }); }; -const Mockstore: React.FC = ({ pokedexState, children }) => ( - {children} +const Mockstore: React.FC = ({ + pokedexState, + filterState, + children, +}) => ( + {children} ); const meta: Meta = { @@ -105,21 +132,53 @@ export default meta; export const Loding = { decorators: [ (story: () => React.ReactNode) => ( - {story()} + + {story()} + ), ], }; -export const Primary = { +export const All = { decorators: [ (story: () => React.ReactNode) => ( - {story()} + + {story()} + + ), + ], + args: { + selectedRegion: 'kanto', + }, +}; + +const filterStateOnlyFire = { + regionOptions: [], + typeOptions: [], + sortOptions: [], + selectedRegion: 'kanto', + selectedType: 'fire', + selectedSort: 'id', + searchInput: '', +}; +export const typeFireSelected = { + decorators: [ + (story: () => React.ReactNode) => ( + + {story()} + ), ], args: { selectedRegion: 'kanto', - selectedType: 'All Types', - selectedSort: 'id', - searchInput: '', }, }; diff --git a/src/features/Pokedex/Pokedex.tsx b/src/features/Pokedex/Pokedex.tsx index c30965a..efb95b9 100644 --- a/src/features/Pokedex/Pokedex.tsx +++ b/src/features/Pokedex/Pokedex.tsx @@ -11,17 +11,9 @@ import { fetchSelectedPokemonInfo } from 'features/InfoDialog/infoDialogSlice'; export interface PokedexProps { selectedRegion: string; - selectedType: string; - selectedSort: string; - searchInput: string; } -const Pokedex = ({ - selectedRegion, - selectedType, - selectedSort, - searchInput, -}: PokedexProps) => { +const Pokedex = ({ selectedRegion }: PokedexProps) => { const dispatch = useAppDispatch(); const isLoadingPokemons = useAppSelector(