Fixed most warning in pokeApi.ts and Pokedex.tsx

develop
Jason Zhu 2023-05-19 22:48:15 +10:00
parent 4a13b56c98
commit bde86898e2
2 changed files with 8 additions and 13 deletions

View File

@ -2,6 +2,7 @@ import {
fetchBaseQuery, fetchBaseQuery,
FetchArgs, FetchArgs,
createApi, createApi,
BaseQueryApi,
} from '@reduxjs/toolkit/query/react'; } from '@reduxjs/toolkit/query/react';
import { import {
RegionListResponseData, RegionListResponseData,
@ -9,6 +10,7 @@ import {
PokemonResponseData, PokemonResponseData,
EvolutionChainResponseData, EvolutionChainResponseData,
PokemonSpeciesResponseData, PokemonSpeciesResponseData,
nameUrlPair,
} from 'types/api'; } from 'types/api';
export interface pokeApiFullListFetchArgs extends FetchArgs { export interface pokeApiFullListFetchArgs extends FetchArgs {
@ -19,12 +21,7 @@ interface PokeAPIPaginatedResponse {
count: number; count: number;
next: string | null; next: string | null;
previous: string | null; previous: string | null;
results: any[]; results: nameUrlPair[];
}
interface PokeAPIFullListResponse {
count: number;
results: any[];
} }
export const getIdFromUrl = (url: string) => { export const getIdFromUrl = (url: string) => {
@ -33,7 +30,7 @@ export const getIdFromUrl = (url: string) => {
}; };
async function fetchAllPages(url: string | null) { async function fetchAllPages(url: string | null) {
const allResults: any[] = []; const allResults: nameUrlPair[] = [];
while (url) { while (url) {
const response = await fetch(url); const response = await fetch(url);
@ -50,7 +47,7 @@ export const paginationBaseQuery = (baseUrl: string) =>
export const pokeApiAllPagesCustomBaseQuery = async ( export const pokeApiAllPagesCustomBaseQuery = async (
args: pokeApiFullListFetchArgs, args: pokeApiFullListFetchArgs,
api: any, api: BaseQueryApi,
extra: any, extra: any,
baseUrl: string, baseUrl: string,
) => { ) => {
@ -62,19 +59,17 @@ export const pokeApiAllPagesCustomBaseQuery = async (
data.results = data.results.concat(allResults); data.results = data.results.concat(allResults);
} }
const fullListReponse: PokeAPIFullListResponse = { result.data = {
count: data.count, count: data.count,
results: data.results, results: data.results,
}; };
result.data = fullListReponse;
} }
return result; return result;
}; };
export const pokeApiBaseQuery = async ( export const pokeApiBaseQuery = async (
args: pokeApiFullListFetchArgs, args: pokeApiFullListFetchArgs,
api: any, api: BaseQueryApi,
extra: any, extra: any,
) => { ) => {
const baseUrl = 'https://pokeapi.co/api/v2/'; const baseUrl = 'https://pokeapi.co/api/v2/';

View File

@ -76,7 +76,7 @@ const Pokedex = ({
useEffect(() => { useEffect(() => {
dispatch(fetchPokemonsInTheRegion(selectedRegion)); dispatch(fetchPokemonsInTheRegion(selectedRegion));
}, [selectedRegion]); }, [dispatch, selectedRegion]);
return ( return (
<> <>