Skip to content

Commit

Permalink
Filtro de categorias
Browse files Browse the repository at this point in the history
Adicionado recurso de filtro na página de categorias para selecionar livros por categorias como front-end, back-end ou dados.
  • Loading branch information
wellingtonfernandesbarbosa committed Jul 1, 2023
1 parent 8a5d8c9 commit 98335b7
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 5 deletions.
5 changes: 2 additions & 3 deletions app/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ getBuscarLivrosDaApi();
async function getBuscarLivrosDaApi() {
const res = await fetch(endpointDaApi);
livros = await res.json();
console.table(livros);
let livrosComDesconto = aplicarDesconto(livros)
let livrosComDesconto = aplicarDesconto(livros);
exibirOsLivrosNaTela(livrosComDesconto);
}
};
10 changes: 10 additions & 0 deletions app/metodoFilter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
const botoes = document.querySelectorAll('.btn');

botoes.forEach(btn => btn.addEventListener('click', filtrarLivros));

function filtrarLivros() {
const elementoBtn = document.getElementById(this.id);
const categoria = elementoBtn.value;
let livrosFiltrados = livros.filter(livro => livro.categoria == categoria);
exibirOsLivrosNaTela(livrosFiltrados);
};
4 changes: 2 additions & 2 deletions app/metodoForEach.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const elementoParaInserirLivros = document.getElementById('livros');


function exibirOsLivrosNaTela(listaDeLivros){
elementoParaInserirLivros.innerHTML = '';
listaDeLivros.forEach(livro => {
elementoParaInserirLivros.innerHTML += `
<div class="livro">
Expand All @@ -17,4 +17,4 @@ function exibirOsLivrosNaTela(listaDeLivros){
</div>
`;
})
};
};
1 change: 1 addition & 0 deletions categorias.html
Original file line number Diff line number Diff line change
Expand Up @@ -192,5 +192,6 @@ <h2 class="rodape__titulo">Grupo Alura</h2>
<script src="app/main.js"></script>
<script src="app/metodoForEach.js"></script>
<script src="app/metodoMap.js"></script>
<script src="app/metodoFilter.js"></script>
</body>
</html>

1 comment on commit 98335b7

@vercel
Copy link

@vercel vercel bot commented on 98335b7 Jul 1, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.