Commit db476722 authored by Ondrej Bazala's avatar Ondrej Bazala
Browse files

Added new attributes to Pokemon type

parent c4f26349
This diff is collapsed.
type Stat = {
name: string;
amount: number;
};
export type Pokemon = {
id: number;
name: string;
sprite: string;
weight: number;
height: number;
types: string[];
abilities: string[];
stats: Stat[];
};
export type PokemonOnCanvas = {
......@@ -16,6 +26,11 @@ export type PokemonResponse = {
id: number;
name: string;
sprites: { front_default: string };
weight: number;
height: number;
types: any;
abilities: any;
stats: any;
};
export const getPokemons = async () => {
......@@ -24,15 +39,26 @@ export const getPokemons = async () => {
ids.map(async id => {
const response = await fetch(`https://pokeapi.co/api/v2/pokemon/${id}`);
const pokemonDetail = await response.json();
console.log(transformPokemon(pokemonDetail));
console.log(pokemonDetail);
return transformPokemon(pokemonDetail);
})
);
console.log(await pokemons);
};
// TODO: modify this function to get everything we want from the API, provide custom fields if desired
const transformPokemon = (pokemon: PokemonResponse) => {
const { id, name, sprites } = pokemon;
return { id, name, sprite: sprites.front_default };
const { id, name, sprites, weight, height, types, abilities, stats } =
pokemon;
return {
id,
name,
sprite: sprites.front_default,
weight,
height
//types: types.map(t => t.type.name),
//abilities: abilities.map(a => a.ability.name),
//stats: stats.map(s => {
// return { name: s.stat.name, amount: s.base_stat};
//})
};
};
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment