Skip to content
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

adicionando desafio pokedex - transforma tec #296

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
3 changes: 3 additions & 0 deletions Pasta - Pokedex/.vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"liveServer.settings.port": 5501
}
21 changes: 21 additions & 0 deletions Pasta - Pokedex/assets/css/global.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
* {
font-family: 'Roboto', sans-serif;
box-sizing: border-box;
}
body{
background-color: #f6f8fc ;
}
.content{
height: 100vh;
width: 100%;
padding: 1rem;
background-color: #fff;

}
@media screen and(min-width: 992px) {
.content{
max-width: 992px;
margin: 0 auto;
margin: 1rem auto;
}
}
88 changes: 88 additions & 0 deletions Pasta - Pokedex/assets/css/pokedex.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
.pokemons {
display: grid;
grid-template-columns: 1fr 1fr;
padding: 0;
margin: 0;
list-style: none;
}

@media screen and (min-width: 576px) {
.pokemons {
grid-template-columns: 1fr 1fr 1fr;
}
}

@media screen and (min-width: 992px) {
.pokemons {
grid-template-columns: 1fr 1fr 1fr 1fr;
}
}

.pokemon {
display: flex;
flex-direction: column;
margin: .5rem;
padding: 1rem;
border-radius: 1rem;
background-color: #4bc1df;
}

.pokemon .number {
color: #e40808;
opacity: .3;
text-align: right;
font-size: .625rem;
}

.pokemon .name {
text-transform: capitalize;
color: #ffffff;
margin-bottom: .25rem;
}

.pokemon .detail {
display: flex;
flex-direction: row;
align-items: center;
justify-content: space-between;
}

.pokemon .detail .types {
padding: 0;
margin: 0;
list-style: none;
}

.pokemon .detail .types .type {
color: #fff;
padding: .25rem .5rem;
margin: .25rem 0;
font-size: .625rem;
border-radius: 1rem;
filter: brightness(1.1);
text-align: center;
}

.pokemon .detail img {
max-width: 100%;
height: 70px;
}

.pagination {
display: flex;
flex-direction: row;
justify-content: center;
align-items: center;
width: 100%;
padding: 1rem;
}

.pagination button {
padding: .25rem .5rem;
margin: .25rem 0;
font-size: .625rem;
color: #fff;
background-color: #bc6cdb;
border: none;
border-radius: 1rem;
}
47 changes: 47 additions & 0 deletions Pasta - Pokedex/assets/js/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
const pokemonList = document.getElementById('pokemonList')
const loadMoreButton = document.getElementById('loadMoreButton')

const maxRecords = 151
const limit = 10
let offset = 0;

function convertPokemonToLi(pokemon) {
return `
<li class="pokemon ${pokemon.type}">
<span class="number">#${pokemon.number}</span>
<span class="name">${pokemon.name}</span>

<div class="detail">
<ol class="types">
${pokemon.types.map((type) => `<li class="type ${type}">${type}</li>`).join('')}
</ol>

<img src="${pokemon.photo}"
alt="${pokemon.name}">
</div>
</li>
`
}

function loadPokemonItens(offset, limit) {
pokeApi.getPokemons(offset, limit).then((pokemons = []) => {
const newHtml = pokemons.map(convertPokemonToLi).join('')
pokemonList.innerHTML += newHtml
})
}

loadPokemonItens(offset, limit)

loadMoreButton.addEventListener('click', () => {
offset += limit
const qtdRecordsWithNexPage = offset + limit

if (qtdRecordsWithNexPage >= maxRecords) {
const newLimit = maxRecords - offset
loadPokemonItens(offset, newLimit)

loadMoreButton.parentElement.removeChild(loadMoreButton)
} else {
loadPokemonItens(offset, limit)
}
})
35 changes: 35 additions & 0 deletions Pasta - Pokedex/assets/js/poke-api.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@

const pokeApi = {}

function convertPokeApiDetailToPokemon(pokeDetail) {
const pokemon = new Pokemon()
pokemon.number = pokeDetail.id
pokemon.name = pokeDetail.name

const types = pokeDetail.types.map((typeSlot) => typeSlot.type.name)
const [type] = types

pokemon.types = types
pokemon.type = type

pokemon.photo = pokeDetail.sprites.other.dream_world.front_default

return pokemon
}

pokeApi.getPokemonDetail = (pokemon) => {
return fetch(pokemon.url)
.then((response) => response.json())
.then(convertPokeApiDetailToPokemon)
}

pokeApi.getPokemons = (offset = 0, limit = 5) => {
const url = `https://pokeapi.co/api/v2/pokemon?offset=${offset}&limit=${limit}`

return fetch(url)
.then((response) => response.json())
.then((jsonBody) => jsonBody.results)
.then((pokemons) => pokemons.map(pokeApi.getPokemonDetail))
.then((detailRequests) => Promise.all(detailRequests))
.then((pokemonsDetails) => pokemonsDetails)
}
8 changes: 8 additions & 0 deletions Pasta - Pokedex/assets/js/pokemon-model.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@

class Pokemon {
number;
name;
type;
types = [];
photo;
}
Binary file added Pasta - Pokedex/img/3_-_Venusaur.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Pasta - Pokedex/img/esg.futurebrand.com.webp
Binary file not shown.
Binary file added Pasta - Pokedex/img/pikachu.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Pasta - Pokedex/img/pngegg(1).png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Pasta - Pokedex/img/pngegg.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Pasta - Pokedex/img/pngwing.com(9).png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
46 changes: 46 additions & 0 deletions Pasta - Pokedex/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<!DOCTYPE html>
<html lang="pt-BR">

<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Pokedex</title>

<!-- Normalize CSS -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/normalize/8.0.1/normalize.min.css"
integrity="sha512-NhSC1YmyruXifcj/KFRWoC561YpHpc5Jtzgvbuzx5VozKpWvQ+4nXhPdFgmx8xqexRcpAglTj9sIBWINXa8x5w=="
crossorigin="anonymous" referrerpolicy="no-referrer" />

<!-- Font Roboto -->
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Roboto:wght@100;300;500;700&display=swap" rel="stylesheet">

<!-- Nosso CSS -->
<link rel="stylesheet" href="/assets/css/global.css">
<link rel="stylesheet" href="/assets/css/pokedex.css">
</head>

<body>
<section class="content">
<h1>Pokedex</h1>

<ol id="pokemonList" class="pokemons">
<!-- lista de pokemons -->
</ol>
<div class="pagination">
<button id="loadMoreButton" type="button">
Carregar mais
</button>
</div>

</section>

<!-- NOSSO JS -->
<script src="/assets/js/pokemon-model.js"></script>
<script src="/assets/js/poke-api.js"></script>
<script src="/assets/js/main.js"></script>
</body>

</html>
54 changes: 54 additions & 0 deletions Pasta - Pokedex/index2.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<li class="pokemon">
<span class="number">#001</span>
<span class="name">Bulbassaur</span>

<div class="detail">
<ol class="types">
<li class="type">grass</li>
<li class="type">poison</li>

</ol>
<img src="img/pngwing.com(9).png" alt="Bulbassaur">
</div>

</li>
<li li class="pokemon">
<span class="number">#002</span>
<span class="name">Ivyssaur</span>
<div class="detail">
<ol class="types">
<li class="type">grass</li>
<li class="type">poison</li>
</ol>
<img src="img/pngegg.png" alt="Ivyssaur">
</li>
<li li class="pokemon">
<span class="number">#003</span>
<span class="name">Venussar</span>
<div class="detail">
<ol class="types">
<li class="type">grass</li>
<li class="type">poison</li>
</ol>
<img src="img/dck5nef-518de8dd-4143-4285-924b-8d3bdedcc187.png" alt="Venussar">
</li>
<li li class="pokemon">
<span class="number">#004</span>
<span class="name">Pikachu</span>
<div class="detail">
<ol class="types">
<li class="type">grass</li>
<li class="type">poison</li>
</ol>
<img src="img/pikachu.png" alt="Pikachu">
</li>
<li li class="pokemon">
<span class="number">#005</span>
<span class="name">Charizard</span>
<div class="detail">
<ol class="types">
<li class="type">grass</li>
<li class="type">poison</li>
</ol>
<img src="img/pngegg(1).png" alt="Charizard">
</li>
12 changes: 12 additions & 0 deletions Pasta - Pokedex/node_modules/.package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading