Skip to content

Commit e8e7ead

Browse files
Merge pull request #9 from MiquelRForgeFlow/main-truly-get-correct-name
[FIX] Truly get correct pokemon name
2 parents 12b6ec8 + 18c22fc commit e8e7ead

File tree

3 files changed

+16
-8
lines changed

3 files changed

+16
-8
lines changed

main.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ function renderPokemonIndex(pokemons: Array<Pokemon>): string {
1111
const pokemonLinks = pokemons.map(
1212
(pokemon) => `
1313
<li>
14-
<a class="pokemon-card" href="${String(pokemon.id).padStart(4, '0')}_${pokemon.name}.html" data-types='${JSON.stringify(pokemon.types)}' data-baby='${pokemon.is_baby}' data-legendary='${pokemon.is_legendary}' data-mythical='${pokemon.is_mythical}' style="background-image: linear-gradient(135deg, ${getTypeColor(toPokemonType(pokemon.types[0]))} 0%, ${getTypeColor(toPokemonType(pokemon.types[0]))} 50%, ${pokemon.types[1] ? getTypeColor(toPokemonType(pokemon.types[1])) : getTypeColor(toPokemonType(pokemon.types[0]))} 50%, ${pokemon.types[1] ? getTypeColor(toPokemonType(pokemon.types[1])) : getTypeColor(toPokemonType(pokemon.types[0]))} 100%);">
14+
<a class="pokemon-card" href="${String(pokemon.id).padStart(4, '0')}_${pokemon.codename}.html" data-types='${JSON.stringify(pokemon.types)}' data-baby='${pokemon.is_baby}' data-legendary='${pokemon.is_legendary}' data-mythical='${pokemon.is_mythical}' style="background-image: linear-gradient(135deg, ${getTypeColor(toPokemonType(pokemon.types[0]))} 0%, ${getTypeColor(toPokemonType(pokemon.types[0]))} 50%, ${pokemon.types[1] ? getTypeColor(toPokemonType(pokemon.types[1])) : getTypeColor(toPokemonType(pokemon.types[0]))} 50%, ${pokemon.types[1] ? getTypeColor(toPokemonType(pokemon.types[1])) : getTypeColor(toPokemonType(pokemon.types[0]))} 100%);">
1515
<div class="pokemon-id">#${String(pokemon.id).padStart(4, '0')}</div>
1616
<img src="${pokemon.imageUrl}" alt="${pokemon.name}" />
17-
<h2>${pokemon.name.charAt(0).toUpperCase() + pokemon.name.slice(1)}</h2>
17+
<h2>${pokemon.name}</h2>
1818
</a>
1919
</li>`
2020
).join('\n');
@@ -83,7 +83,7 @@ function renderPokemonIndex(pokemons: Array<Pokemon>): string {
8383
const isBaby = JSON.parse(pokemonCard.dataset.baby);
8484
const isLegendary = JSON.parse(pokemonCard.dataset.legendary);
8585
const isMythical = JSON.parse(pokemonCard.dataset.mythical);
86-
const nameMatch = searchText === "" || pokemonName.includes(searchText);
86+
const nameMatch = searchText === "" || pokemonName.includes(searchText.toLowerCase());
8787
const typeMatch = selectedType === "" || pokemonTypes.includes(selectedType);
8888
const babyMatch = !babyFilter || isBaby;
8989
const legendaryMatch = !legendaryFilter || isLegendary;
@@ -171,7 +171,7 @@ function renderPokemonIndex(pokemons: Array<Pokemon>): string {
171171
<html>
172172
${head(pokemon.name)}
173173
<body>
174-
<h1><a href="index.html" class="back-to-menu"><i class="fas fa-arrow-left"></i></a> ${pokemon.name.charAt(0).toUpperCase() + pokemon.name.slice(1)} <span class="pokemon-id">#${String(pokemon.id).padStart(4, '0')}</span></h1>
174+
<h1><a href="index.html" class="back-to-menu"><i class="fas fa-arrow-left"></i></a> ${pokemon.name} <span class="pokemon-id">#${String(pokemon.id).padStart(4, '0')}</span></h1>
175175
<div class="pokemon-container">
176176
<img src="${pokemon.officialArtworkUrl}" alt="${pokemon.name}" />
177177
<table>
@@ -300,6 +300,6 @@ function head(title: string): string {
300300
continue;
301301
}
302302
const detailHtml = renderPokemonDetail(pokemonDetail);
303-
await writeFile(`${String(pokemonDetail.id).padStart(4, '0')}_${pokemonDetail.name}.html`, detailHtml);
303+
await writeFile(`${String(pokemonDetail.id).padStart(4, '0')}_${pokemonDetail.codename}.html`, detailHtml);
304304
}
305305
})();

pokemon-detail.ts

+6-2
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ export class PokemonDetails {
2424
constructor(
2525
public id: number,
2626
public name: string,
27+
public codename: string,
2728
public imageUrl: string,
2829
public officialArtworkUrl: string,
2930
public height: number,
@@ -69,10 +70,13 @@ export class PokemonDetails {
6970
});
7071
const damageRelations = await getPokemonDamageRelations(id);
7172
const pokedexDescriptions = await getPokemonDescriptions(id);
72-
const name = data2.names.find((entry: { language: { name: string } }) => entry.language.name === 'en');
73+
const codename = data.species.name;
74+
const nameEntry = data2.names.find((entry: { language: { name: string } }) => entry.language.name === 'en');
75+
const name = nameEntry ? nameEntry.name : codename.charAt(0).toUpperCase() + codename.slice(1);
7376
return new PokemonDetails(
7477
id,
75-
name ? name.name : data.species.name,
78+
name,
79+
codename,
7680
imageUrl,
7781
officialArtworkUrl,
7882
height,

pokemon.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ export class Pokemon {
44
constructor(
55
public id: number,
66
public name: string,
7+
public codename: string,
78
public imageUrl: string,
89
public types: string[],
910
public is_baby: boolean,
@@ -33,8 +34,11 @@ export class Pokemon {
3334
const is_baby = speciesData.is_baby;
3435
const is_legendary = speciesData.is_legendary;
3536
const is_mythical = speciesData.is_mythical;
37+
const codename = data.species.name;
38+
const nameEntry = data2.names.find((entry: { language: { name: string } }) => entry.language.name === 'en');
39+
const name = nameEntry ? nameEntry.name : codename.charAt(0).toUpperCase() + codename.slice(1);
3640

37-
pokemons.push(new Pokemon(i, data.species.name, imageUrl, types, is_baby, is_legendary, is_mythical));
41+
pokemons.push(new Pokemon(i, name, codename, imageUrl, types, is_baby, is_legendary, is_mythical));
3842
} else {
3943
console.error(`Error fetching data for Pokémon ID ${i}: ${response.statusText}`);
4044
}

0 commit comments

Comments
 (0)