forked from SebasAriasDEV/p2-typescript-2023
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4ededa0
commit 53a4e33
Showing
9 changed files
with
136 additions
and
1,551 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 ` | ||
<h1>${name.toUpperCase()}</h1> | ||
<hr /> | ||
<div class="row"> | ||
<div class="col-3" style="text-align: center;"> | ||
<img | ||
src="${pokemonImg}" | ||
/> | ||
</div> | ||
<div class="col-9"> | ||
<div class="row mb-3"> | ||
<div class="col-4"> | ||
<div class="stats-card ${hpStats.base_stat <= 50 ? 'bad-stat' :'good-stat'}"> | ||
<p class="stat-title">Hp:</p> | ||
<p class="stat-number">${hpStats.base_stat}</p> | ||
</div> | ||
</div> | ||
<div class="col-4"> | ||
<div class="stats-card ${attackStats.base_stat <= 50 ? 'bad-stat' :'good-stat'}"> | ||
<p class="stat-title">Attack:</p> | ||
<p class="stat-number">${attackStats.base_stat}</p> | ||
</div> | ||
</div> | ||
<div class="col-4"> | ||
<div class="stats-card ${defenseStat.base_stat <= 50 ? 'bad-stat' :'good-stat'}"> | ||
<p class="stat-title">Defense:</p> | ||
<p class="stat-number">${defenseStat.base_stat}</p> | ||
</div> | ||
</div> | ||
</div> | ||
<div class="row"> | ||
<div class="col-4"> | ||
<div class="stats-card ${specialAttStats.base_stat <= 50 ? 'bad-stat' :'good-stat'}"> | ||
<p class="stat-title">Special Attack:</p> | ||
<p class="stat-number">${specialAttStats.base_stat}</p> | ||
</div> | ||
</div> | ||
<div class="col-4"> | ||
<div class="stats-card ${specialDefStats.base_stat <= 50 ? 'bad-stat' :'good-stat'}"> | ||
<p class="stat-title">Special Defense:</p> | ||
<p class="stat-number">${specialDefStats.base_stat}</p> | ||
</div> | ||
</div> | ||
<div class="col-4"> | ||
<div class="stats-card ${speedStats.base_stat <= 50 ? 'bad-stat' :'good-stat'}"> | ||
<p class="stat-title">Speed:</p> | ||
<p class="stat-number">${speedStats.base_stat}</p> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
`; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
const onSeeMore = (pokemonUrl) => { | ||
localStorage.setItem('pokemonUrl', pokemonUrl); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.