Skip to content

[FIX] Get correct pokemon name #8

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion pokemon-detail.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ export class PokemonDetails {
try {
const response = await fetch(`https://pokeapi.co/api/v2/pokemon/${id}`);
const data = await response.json();
const response2 = await fetch(`https://pokeapi.co/api/v2/pokemon-species/${id}`);
const data2 = await response2.json();
const imageUrl = data.sprites.front_default;
const officialArtworkUrl = data.sprites.other["official-artwork"].front_default;
const height = data.height;
Expand All @@ -67,9 +69,10 @@ export class PokemonDetails {
});
const damageRelations = await getPokemonDamageRelations(id);
const pokedexDescriptions = await getPokemonDescriptions(id);
const name = data2.names.find((entry: { language: { name: string } }) => entry.language.name === 'en');
return new PokemonDetails(
id,
data.species.name,
name ? name.name : data.species.name,
imageUrl,
officialArtworkUrl,
height,
Expand Down