Skip to content

Commit

Permalink
Aula 4 finalizada!!
Browse files Browse the repository at this point in the history
Commit para a Main da aula 4 da Imersão Front-end da Alura!!
  • Loading branch information
lucasvalgoi committed Jan 29, 2024
1 parent d3d3fbf commit 29851d0
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 4 deletions.
10 changes: 6 additions & 4 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@

<!-- PLAYLIST -->
<div class="playlist-container">
<div id="playlist-result">
<div id="result-playlists">
<div class="playlist">
<h1 class="greeting">Boa Tarde</h1>
<h2 class="session">Navegar por todas as seções</h2>
Expand Down Expand Up @@ -240,9 +240,9 @@ <h2 class="session">Navegar por todas as seções</h2>
</div>
</div>
<div class="card-text">
<a title="Foo Fighters" class="vst" href="">
<span class="artist-name" id="artist-name"></span>
<span class="artist-categorie">Artista</span>
<a title="Foo Fighters" class="vst" href=""></a>
<span class="artist-name" id="artist-name"></span>
<span class="artist-categorie">Artista</span>
</a>
</div>
</div>
Expand All @@ -262,5 +262,7 @@ <h2 class="session">Navegar por todas as seções</h2>
<button>Inscreva-se de graça </button>
</div>
</footer>

<script type="text/javascript" src="./script.js"></script>
</body>
</html>
34 changes: 34 additions & 0 deletions script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
const searchInput = document.getElementById('search-input');
const resultArtist = document.getElementById('result-artist');
const resultPlaylist = document.getElementById('result-playlists');

function requestApi(searchTerm) {
const url = `http://localhost:3000/artists?name_like=${searchTerm}`
fetch(url)
.then((response) => response.json())
.then((result) => displayResults(result))
}

function displayResults(result) {
resultPlaylist.classList.add('hidden');
const artistName = document.getElementById('artist-name');
const artistImage = document.getElementById('artist-img');

result.forEach(element => {
artistName.innerText = element.name;
artistImage.src = element.urlImg;
});

resultArtist.classList.remove('hidden');
}

document.addEventListener('input', function() {
const searchTerm = searchInput.value.toLowerCase();
if (searchTerm === '') {
resultPlaylist.classList.add('hidden');
resultArtist.classList.remove('hidden');
return;
}

requestApi(searchTerm);
})

0 comments on commit 29851d0

Please sign in to comment.