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 = { export type Pokemon = {
id: number; id: number;
name: string; name: string;
sprite: string; sprite: string;
weight: number;
height: number;
types: string[];
abilities: string[];
stats: Stat[];
}; };
export type PokemonOnCanvas = { export type PokemonOnCanvas = {
...@@ -16,6 +26,11 @@ export type PokemonResponse = { ...@@ -16,6 +26,11 @@ export type PokemonResponse = {
id: number; id: number;
name: string; name: string;
sprites: { front_default: string }; sprites: { front_default: string };
weight: number;
height: number;
types: any;
abilities: any;
stats: any;
}; };
export const getPokemons = async () => { export const getPokemons = async () => {
...@@ -24,15 +39,26 @@ export const getPokemons = async () => { ...@@ -24,15 +39,26 @@ export const getPokemons = async () => {
ids.map(async id => { ids.map(async id => {
const response = await fetch(`https://pokeapi.co/api/v2/pokemon/${id}`); const response = await fetch(`https://pokeapi.co/api/v2/pokemon/${id}`);
const pokemonDetail = await response.json(); const pokemonDetail = await response.json();
console.log(transformPokemon(pokemonDetail)); console.log(pokemonDetail);
return transformPokemon(pokemonDetail); return transformPokemon(pokemonDetail);
}) })
); );
console.log(await pokemons); 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 transformPokemon = (pokemon: PokemonResponse) => {
const { id, name, sprites } = pokemon; const { id, name, sprites, weight, height, types, abilities, stats } =
return { id, name, sprite: sprites.front_default }; 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};
//})
};
}; };
Supports Markdown
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