diff --git a/apis/fecth-pokemons.ts b/apis/fecth-pokemons.ts index 1ac0103..d5cecba 100644 --- a/apis/fecth-pokemons.ts +++ b/apis/fecth-pokemons.ts @@ -13,9 +13,10 @@ export const loadPokemons = async (count: number): Promise => { const responseDetails = await fetch(detailsURL); const jsonDetails: any = await responseDetails.json(); - const { base_experience, height, weight, sprites } = jsonDetails; + const { id, base_experience, height, weight, sprites } = jsonDetails; const pokemonImg = sprites.other.dream_world.front_default; + pokemon.id = id; pokemon.experience = base_experience; pokemon.height = height; pokemon.weight = weight; diff --git a/dom/load-details.js b/dom/load-details.js new file mode 100644 index 0000000..3d779aa --- /dev/null +++ b/dom/load-details.js @@ -0,0 +1,103 @@ +const fetchDetails = async (urlString) => { + const response = await fetch(urlString); + const jsonData = await response.json(); + + const { id, name, stats, sprites } = jsonData; + const pokemonImg = sprites.other.dream_world.front_default; + const [ + hpStats, + attackStats, + defenseStat, + specialAttStats, + specialDefStats, + speedStats, + ] = stats; + + console.log(id, name, hpStats.base_stat, attackStats.base_stat); + return { + name, + hpStats, + attackStats, + defenseStat, + specialAttStats, + specialDefStats, + speedStats, + pokemonImg, + }; +}; + +window.addEventListener('DOMContentLoaded', async () => { + const currentUrl = localStorage.getItem('pokemonUrl'); + console.log('URL', currentUrl); + const details = await fetchDetails(currentUrl); + const htmlContent = renderDetailsHtml(details); + document.querySelector('#root').innerHTML = htmlContent; + console.log(details); +}); + +const renderDetailsHtml = ({ + name, + hpStats, + attackStats, + defenseStat, + specialAttStats, + specialDefStats, + speedStats, + pokemonImg, +}) => { + return ` +

${name.toUpperCase()}

+
+ +
+
+ +
+ +
+
+
+
+

Hp:

+

${hpStats.base_stat}

+
+
+
+
+

Attack:

+

${attackStats.base_stat}

+
+
+
+
+

Defense:

+

${defenseStat.base_stat}

+
+
+
+
+
+
+

Special Attack:

+

${specialAttStats.base_stat}

+
+
+
+
+

Special Defense:

+

${specialDefStats.base_stat}

+
+
+
+
+

Speed:

+

${speedStats.base_stat}

+
+
+
+
+
+ `; +}; diff --git a/dom/see-details-button.js b/dom/see-details-button.js new file mode 100644 index 0000000..7154d15 --- /dev/null +++ b/dom/see-details-button.js @@ -0,0 +1,3 @@ +const onSeeMore = (pokemonUrl) => { + localStorage.setItem('pokemonUrl', pokemonUrl); +}; diff --git a/helpers/render-files.ts b/helpers/render-files.ts index 7bc6398..0834b91 100644 --- a/helpers/render-files.ts +++ b/helpers/render-files.ts @@ -35,9 +35,9 @@ const renderUsers = (pokemons: Pokemon[]) => {
  • Weight: ${pokemon.weight}
  • See more @@ -61,6 +61,7 @@ export const render = (pokemons: Pokemon[]) => {
    ${renderUsers(pokemons)}
    + `; diff --git a/index.ts b/index.ts index 2b3bb2d..19f6198 100644 --- a/index.ts +++ b/index.ts @@ -3,6 +3,6 @@ import { writeFile } from 'fs/promises'; import { loadPokemons } from './apis/fecth-pokemons.js'; import { render } from './helpers/render-files.js'; -const pokemons = await loadPokemons(50); +const pokemons = await loadPokemons(2); const indexHTML = render(pokemons); await writeFile('pokemons.html', indexHTML); \ No newline at end of file diff --git a/models/pokemon-model.ts b/models/pokemon-model.ts index 5f61fae..f185099 100644 --- a/models/pokemon-model.ts +++ b/models/pokemon-model.ts @@ -1,4 +1,5 @@ export class Pokemon { + id: string; name: string; url: string; weight: number; @@ -7,6 +8,7 @@ export class Pokemon { image: string; constructor( + id: string, name: string, url: string, height: number, @@ -14,7 +16,7 @@ export class Pokemon { experience: number, image: string ) { - this.name = name; + (this.id = id), (this.name = name); this.url = url; this.weight = weight; this.height = height; diff --git a/pokemon-details.html b/pokemon-details.html index c74b115..e035505 100644 --- a/pokemon-details.html +++ b/pokemon-details.html @@ -14,60 +14,10 @@ -

    Pokemon Name

    -
    +
    +

    -
    -
    - -
    - -
    -
    -
    -
    -

    HP:

    -

    350

    -
    -
    -
    -
    -

    HP:

    -

    350

    -
    -
    -
    -
    -

    HP:

    -

    350

    -
    -
    -
    -
    -
    -
    -

    HP:

    -

    350

    -
    -
    -
    -
    -

    HP:

    -

    350

    -
    -
    -
    -
    -

    HP:

    -

    350

    -
    -
    -
    -
    -
    - - + + diff --git a/pokemons.html b/pokemons.html index 3e031e3..1663059 100644 --- a/pokemons.html +++ b/pokemons.html @@ -36,9 +36,9 @@
    BULBASAUR
  • Weight: 69
  • See more @@ -67,1497 +67,9 @@
    IVYSAUR
  • Weight: 130
  • See more - - - - - - -
    -
    -
    -
    - ... -
    -
    -
    -
    VENUSAUR
    - -
      -
    • Experience: 263
    • -
    • Height: 20
    • -
    • Weight: 1000
    • -
    - See more -
    -
    -
    -
    -
    - -
    -
    -
    -
    - ... -
    -
    -
    -
    CHARMANDER
    - -
      -
    • Experience: 62
    • -
    • Height: 6
    • -
    • Weight: 85
    • -
    - See more -
    -
    -
    -
    -
    - -
    -
    -
    -
    - ... -
    -
    -
    -
    CHARMELEON
    - -
      -
    • Experience: 142
    • -
    • Height: 11
    • -
    • Weight: 190
    • -
    - See more -
    -
    -
    -
    -
    - -
    -
    -
    -
    - ... -
    -
    -
    -
    CHARIZARD
    - -
      -
    • Experience: 267
    • -
    • Height: 17
    • -
    • Weight: 905
    • -
    - See more -
    -
    -
    -
    -
    - -
    -
    -
    -
    - ... -
    -
    -
    -
    SQUIRTLE
    - -
      -
    • Experience: 63
    • -
    • Height: 5
    • -
    • Weight: 90
    • -
    - See more -
    -
    -
    -
    -
    - -
    -
    -
    -
    - ... -
    -
    -
    -
    WARTORTLE
    - -
      -
    • Experience: 142
    • -
    • Height: 10
    • -
    • Weight: 225
    • -
    - See more -
    -
    -
    -
    -
    - -
    -
    -
    -
    - ... -
    -
    -
    -
    BLASTOISE
    - -
      -
    • Experience: 265
    • -
    • Height: 16
    • -
    • Weight: 855
    • -
    - See more -
    -
    -
    -
    -
    - -
    -
    -
    -
    - ... -
    -
    -
    -
    CATERPIE
    - -
      -
    • Experience: 39
    • -
    • Height: 3
    • -
    • Weight: 29
    • -
    - See more -
    -
    -
    -
    -
    - -
    -
    -
    -
    - ... -
    -
    -
    -
    METAPOD
    - -
      -
    • Experience: 72
    • -
    • Height: 7
    • -
    • Weight: 99
    • -
    - See more -
    -
    -
    -
    -
    - -
    -
    -
    -
    - ... -
    -
    -
    -
    BUTTERFREE
    - -
      -
    • Experience: 198
    • -
    • Height: 11
    • -
    • Weight: 320
    • -
    - See more -
    -
    -
    -
    -
    - -
    -
    -
    -
    - ... -
    -
    -
    -
    WEEDLE
    - -
      -
    • Experience: 39
    • -
    • Height: 3
    • -
    • Weight: 32
    • -
    - See more -
    -
    -
    -
    -
    - -
    -
    -
    -
    - ... -
    -
    -
    -
    KAKUNA
    - -
      -
    • Experience: 72
    • -
    • Height: 6
    • -
    • Weight: 100
    • -
    - See more -
    -
    -
    -
    -
    - -
    -
    -
    -
    - ... -
    -
    -
    -
    BEEDRILL
    - -
      -
    • Experience: 178
    • -
    • Height: 10
    • -
    • Weight: 295
    • -
    - See more -
    -
    -
    -
    -
    - -
    -
    -
    -
    - ... -
    -
    -
    -
    PIDGEY
    - -
      -
    • Experience: 50
    • -
    • Height: 3
    • -
    • Weight: 18
    • -
    - See more -
    -
    -
    -
    -
    - -
    -
    -
    -
    - ... -
    -
    -
    -
    PIDGEOTTO
    - -
      -
    • Experience: 122
    • -
    • Height: 11
    • -
    • Weight: 300
    • -
    - See more -
    -
    -
    -
    -
    - -
    -
    -
    -
    - ... -
    -
    -
    -
    PIDGEOT
    - -
      -
    • Experience: 216
    • -
    • Height: 15
    • -
    • Weight: 395
    • -
    - See more -
    -
    -
    -
    -
    - -
    -
    -
    -
    - ... -
    -
    -
    -
    RATTATA
    - -
      -
    • Experience: 51
    • -
    • Height: 3
    • -
    • Weight: 35
    • -
    - See more -
    -
    -
    -
    -
    - -
    -
    -
    -
    - ... -
    -
    -
    -
    RATICATE
    - -
      -
    • Experience: 145
    • -
    • Height: 7
    • -
    • Weight: 185
    • -
    - See more -
    -
    -
    -
    -
    - -
    -
    -
    -
    - ... -
    -
    -
    -
    SPEAROW
    - -
      -
    • Experience: 52
    • -
    • Height: 3
    • -
    • Weight: 20
    • -
    - See more -
    -
    -
    -
    -
    - -
    -
    -
    -
    - ... -
    -
    -
    -
    FEAROW
    - -
      -
    • Experience: 155
    • -
    • Height: 12
    • -
    • Weight: 380
    • -
    - See more -
    -
    -
    -
    -
    - -
    -
    -
    -
    - ... -
    -
    -
    -
    EKANS
    - -
      -
    • Experience: 58
    • -
    • Height: 20
    • -
    • Weight: 69
    • -
    - See more -
    -
    -
    -
    -
    - -
    -
    -
    -
    - ... -
    -
    -
    -
    ARBOK
    - -
      -
    • Experience: 157
    • -
    • Height: 35
    • -
    • Weight: 650
    • -
    - See more -
    -
    -
    -
    -
    - -
    -
    -
    -
    - ... -
    -
    -
    -
    PIKACHU
    - -
      -
    • Experience: 112
    • -
    • Height: 4
    • -
    • Weight: 60
    • -
    - See more -
    -
    -
    -
    -
    - -
    -
    -
    -
    - ... -
    -
    -
    -
    RAICHU
    - -
      -
    • Experience: 243
    • -
    • Height: 8
    • -
    • Weight: 300
    • -
    - See more -
    -
    -
    -
    -
    - -
    -
    -
    -
    - ... -
    -
    -
    -
    SANDSHREW
    - -
      -
    • Experience: 60
    • -
    • Height: 6
    • -
    • Weight: 120
    • -
    - See more -
    -
    -
    -
    -
    - -
    -
    -
    -
    - ... -
    -
    -
    -
    SANDSLASH
    - -
      -
    • Experience: 158
    • -
    • Height: 10
    • -
    • Weight: 295
    • -
    - See more -
    -
    -
    -
    -
    - -
    -
    -
    -
    - ... -
    -
    -
    -
    NIDORAN-F
    - -
      -
    • Experience: 55
    • -
    • Height: 4
    • -
    • Weight: 70
    • -
    - See more -
    -
    -
    -
    -
    - -
    -
    -
    -
    - ... -
    -
    -
    -
    NIDORINA
    - -
      -
    • Experience: 128
    • -
    • Height: 8
    • -
    • Weight: 200
    • -
    - See more -
    -
    -
    -
    -
    - -
    -
    -
    -
    - ... -
    -
    -
    -
    NIDOQUEEN
    - -
      -
    • Experience: 253
    • -
    • Height: 13
    • -
    • Weight: 600
    • -
    - See more -
    -
    -
    -
    -
    - -
    -
    -
    -
    - ... -
    -
    -
    -
    NIDORAN-M
    - -
      -
    • Experience: 55
    • -
    • Height: 5
    • -
    • Weight: 90
    • -
    - See more -
    -
    -
    -
    -
    - -
    -
    -
    -
    - ... -
    -
    -
    -
    NIDORINO
    - -
      -
    • Experience: 128
    • -
    • Height: 9
    • -
    • Weight: 195
    • -
    - See more -
    -
    -
    -
    -
    - -
    -
    -
    -
    - ... -
    -
    -
    -
    NIDOKING
    - -
      -
    • Experience: 253
    • -
    • Height: 14
    • -
    • Weight: 620
    • -
    - See more -
    -
    -
    -
    -
    - -
    -
    -
    -
    - ... -
    -
    -
    -
    CLEFAIRY
    - -
      -
    • Experience: 113
    • -
    • Height: 6
    • -
    • Weight: 75
    • -
    - See more -
    -
    -
    -
    -
    - -
    -
    -
    -
    - ... -
    -
    -
    -
    CLEFABLE
    - -
      -
    • Experience: 242
    • -
    • Height: 13
    • -
    • Weight: 400
    • -
    - See more -
    -
    -
    -
    -
    - -
    -
    -
    -
    - ... -
    -
    -
    -
    VULPIX
    - -
      -
    • Experience: 60
    • -
    • Height: 6
    • -
    • Weight: 99
    • -
    - See more -
    -
    -
    -
    -
    - -
    -
    -
    -
    - ... -
    -
    -
    -
    NINETALES
    - -
      -
    • Experience: 177
    • -
    • Height: 11
    • -
    • Weight: 199
    • -
    - See more -
    -
    -
    -
    -
    - -
    -
    -
    -
    - ... -
    -
    -
    -
    JIGGLYPUFF
    - -
      -
    • Experience: 95
    • -
    • Height: 5
    • -
    • Weight: 55
    • -
    - See more -
    -
    -
    -
    -
    - -
    -
    -
    -
    - ... -
    -
    -
    -
    WIGGLYTUFF
    - -
      -
    • Experience: 218
    • -
    • Height: 10
    • -
    • Weight: 120
    • -
    - See more -
    -
    -
    -
    -
    - -
    -
    -
    -
    - ... -
    -
    -
    -
    ZUBAT
    - -
      -
    • Experience: 49
    • -
    • Height: 8
    • -
    • Weight: 75
    • -
    - See more -
    -
    -
    -
    -
    - -
    -
    -
    -
    - ... -
    -
    -
    -
    GOLBAT
    - -
      -
    • Experience: 159
    • -
    • Height: 16
    • -
    • Weight: 550
    • -
    - See more -
    -
    -
    -
    -
    - -
    -
    -
    -
    - ... -
    -
    -
    -
    ODDISH
    - -
      -
    • Experience: 64
    • -
    • Height: 5
    • -
    • Weight: 54
    • -
    - See more -
    -
    -
    -
    -
    - -
    -
    -
    -
    - ... -
    -
    -
    -
    GLOOM
    - -
      -
    • Experience: 138
    • -
    • Height: 8
    • -
    • Weight: 86
    • -
    - See more -
    -
    -
    -
    -
    - -
    -
    -
    -
    - ... -
    -
    -
    -
    VILEPLUME
    - -
      -
    • Experience: 245
    • -
    • Height: 12
    • -
    • Weight: 186
    • -
    - See more -
    -
    -
    -
    -
    - -
    -
    -
    -
    - ... -
    -
    -
    -
    PARAS
    - -
      -
    • Experience: 57
    • -
    • Height: 3
    • -
    • Weight: 54
    • -
    - See more -
    -
    -
    -
    -
    - -
    -
    -
    -
    - ... -
    -
    -
    -
    PARASECT
    - -
      -
    • Experience: 142
    • -
    • Height: 10
    • -
    • Weight: 295
    • -
    - See more -
    -
    -
    -
    -
    - -
    -
    -
    -
    - ... -
    -
    -
    -
    VENONAT
    - -
      -
    • Experience: 61
    • -
    • Height: 10
    • -
    • Weight: 300
    • -
    - See more -
    -
    -
    -
    -
    - -
    -
    -
    -
    - ... -
    -
    -
    -
    VENOMOTH
    - -
      -
    • Experience: 158
    • -
    • Height: 15
    • -
    • Weight: 125
    • -
    - See more -
    -
    -
    -
    -
    - -
    -
    -
    -
    - ... -
    -
    -
    -
    DIGLETT
    - -
      -
    • Experience: 53
    • -
    • Height: 2
    • -
    • Weight: 8
    • -
    - See more
    @@ -1567,5 +79,6 @@
    DIGLETT
    + diff --git a/styles.css b/styles.css index b3bec3b..7174106 100644 --- a/styles.css +++ b/styles.css @@ -14,6 +14,18 @@ html { padding: 10px; } +.bad-stat { + background-color: rgb(253, 206, 206); + border-color: rgb(250, 80, 80); + color: rgb(246, 28, 28); +} + +.good-stat { + background-color: rgb(177, 218, 189); + border-color: rgb(64, 183, 99); + color: rgb(24, 177, 70); +} + .stat-number { font-size: 32px; text-align: center;