Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Ondřej Bazala
PV247
Commits
db476722
Commit
db476722
authored
Dec 05, 2021
by
Ondrej Bazala
Browse files
Added new attributes to Pokemon type
parent
c4f26349
Changes
2
Expand all
Hide whitespace changes
Inline
Side-by-side
src/data/pokemons.ts
View file @
db476722
This diff is collapsed.
Click to expand it.
src/utils/pokemonFetcher.ts
View file @
db476722
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};
//})
};
};
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment