Move types with pokedexSlice into types/slice.ts

develop
Jason Zhu 2023-04-02 23:51:23 +10:00
parent 40049ef7b5
commit f30edc9700
3 changed files with 30 additions and 32 deletions

View File

@ -4,8 +4,8 @@ import {
setSelectedRegion, setSelectedRegion,
setSelectedType, setSelectedType,
setSelectedSort, setSelectedSort,
setFetchingRegionPokemonList,
} from 'features/Pokedex/pokedexSlice'; } from 'features/Pokedex/pokedexSlice';
import { RegionPokemonRange } from 'features/Pokedex/types/slice';
import { useAppDispatch, useAppSelector } from 'app/hooks'; import { useAppDispatch, useAppSelector } from 'app/hooks';
const useGetSortOptions = () => { const useGetSortOptions = () => {
@ -17,34 +17,27 @@ const useGetSortOptions = () => {
}; };
export const useGetRegionPokemons = () => { export const useGetRegionPokemons = () => {
return { const data: RegionPokemonRange[] = [
data: [ { region: 'kanto', startId: 1, endId: 151 },
{ region: 'kanto', startid: 1, endid: 151 }, { region: 'johto', startId: 152, endId: 251 },
{ region: 'johto', startid: 152, endid: 251 }, { region: 'hoenn', startId: 252, endId: 386 },
{ region: 'hoenn', startid: 252, endid: 386 }, { region: 'sinnoh', startId: 387, endId: 493 },
{ region: 'sinnoh', startid: 387, endid: 493 }, { region: 'unova', startId: 494, endId: 649 },
{ region: 'unova', startid: 494, endid: 649 }, { region: 'kalos', startId: 650, endId: 721 },
{ region: 'kalos', startid: 650, endid: 721 }, { region: 'alola', startId: 722, endId: 809 },
{ region: 'alola', startid: 722, endid: 809 }, { region: 'galar', startId: 810, endId: 898 },
{ region: 'galar', startid: 810, endid: 898 }, ];
], return { data: data };
};
};
export type RegionPokemonRange = {
region: string;
startid: number;
endid: number;
}; };
export const createRegionPokemonListOptionElements = ( export const createRegionPokemonListOptionElements = (
data: RegionPokemonRange[], data: RegionPokemonRange[],
) => { ) => {
return data.map(({ region, startid, endid }) => { return data.map(({ region, startId, endId }) => {
const value = `${region}`; const value = `${region}`;
const label = `${ const label = `${
region.charAt(0).toUpperCase() + region.slice(1) region.charAt(0).toUpperCase() + region.slice(1)
} (${startid}-${endid})`; } (${startId}-${endId})`;
return ( return (
<option key={region} value={value}> <option key={region} value={value}>
{label} {label}

View File

@ -1,24 +1,14 @@
import { createSlice } from '@reduxjs/toolkit'; import { createSlice } from '@reduxjs/toolkit';
import type { PayloadAction } from '@reduxjs/toolkit'; import type { PayloadAction } from '@reduxjs/toolkit';
import { PokemonProps } from './Pokemon'; import { PokedexState } from 'features/Pokedex/types/slice';
import type { RootState } from 'app/store'; import type { RootState } from 'app/store';
import { nameUrlPair } from './types/api'; import { nameUrlPair } from './types/api';
interface PokedexState {
selectedRegion: string;
selectedType: string;
selectedSort: string;
pokemonList: PokemonProps[];
regionPokemonList: nameUrlPair[];
fetchingRegionPokemonList: boolean;
}
const initialState: PokedexState = { const initialState: PokedexState = {
selectedRegion: '', selectedRegion: '',
selectedType: '', selectedType: '',
selectedSort: '', selectedSort: '',
pokemonList: [], pokemonList: [],
regionPokemonList: [],
fetchingRegionPokemonList: false, fetchingRegionPokemonList: false,
}; };

View File

@ -0,0 +1,15 @@
import { PokemonProps } from 'features/Pokedex/Pokemon';
export type PokedexState = {
selectedRegion: string;
selectedType: string;
selectedSort: string;
pokemonList: PokemonProps[];
fetchingRegionPokemonList: boolean;
};
export type RegionPokemonRange = {
region: string;
startId: number;
endId: number;
};