From bde86898e2eb9fc6f10578555bebf201bde61cae Mon Sep 17 00:00:00 2001 From: Jason Zhu Date: Fri, 19 May 2023 22:48:15 +1000 Subject: [PATCH] Fixed most warning in pokeApi.ts and Pokedex.tsx --- src/app/services/pokeApi.ts | 19 +++++++------------ src/features/Pokedex/Pokedex.tsx | 2 +- 2 files changed, 8 insertions(+), 13 deletions(-) diff --git a/src/app/services/pokeApi.ts b/src/app/services/pokeApi.ts index e20ffed..65fc18f 100644 --- a/src/app/services/pokeApi.ts +++ b/src/app/services/pokeApi.ts @@ -2,6 +2,7 @@ import { fetchBaseQuery, FetchArgs, createApi, + BaseQueryApi, } from '@reduxjs/toolkit/query/react'; import { RegionListResponseData, @@ -9,6 +10,7 @@ import { PokemonResponseData, EvolutionChainResponseData, PokemonSpeciesResponseData, + nameUrlPair, } from 'types/api'; export interface pokeApiFullListFetchArgs extends FetchArgs { @@ -19,12 +21,7 @@ interface PokeAPIPaginatedResponse { count: number; next: string | null; previous: string | null; - results: any[]; -} - -interface PokeAPIFullListResponse { - count: number; - results: any[]; + results: nameUrlPair[]; } export const getIdFromUrl = (url: string) => { @@ -33,7 +30,7 @@ export const getIdFromUrl = (url: string) => { }; async function fetchAllPages(url: string | null) { - const allResults: any[] = []; + const allResults: nameUrlPair[] = []; while (url) { const response = await fetch(url); @@ -50,7 +47,7 @@ export const paginationBaseQuery = (baseUrl: string) => export const pokeApiAllPagesCustomBaseQuery = async ( args: pokeApiFullListFetchArgs, - api: any, + api: BaseQueryApi, extra: any, baseUrl: string, ) => { @@ -62,19 +59,17 @@ export const pokeApiAllPagesCustomBaseQuery = async ( data.results = data.results.concat(allResults); } - const fullListReponse: PokeAPIFullListResponse = { + result.data = { count: data.count, results: data.results, }; - - result.data = fullListReponse; } return result; }; export const pokeApiBaseQuery = async ( args: pokeApiFullListFetchArgs, - api: any, + api: BaseQueryApi, extra: any, ) => { const baseUrl = 'https://pokeapi.co/api/v2/'; diff --git a/src/features/Pokedex/Pokedex.tsx b/src/features/Pokedex/Pokedex.tsx index 4131ae3..eaabed8 100644 --- a/src/features/Pokedex/Pokedex.tsx +++ b/src/features/Pokedex/Pokedex.tsx @@ -76,7 +76,7 @@ const Pokedex = ({ useEffect(() => { dispatch(fetchPokemonsInTheRegion(selectedRegion)); - }, [selectedRegion]); + }, [dispatch, selectedRegion]); return ( <>