Commit 34da9fb1 authored by Evan GISDAL's avatar Evan GISDAL

Corrections sur loadArtists pour obtenir id artist et ajout fenetre popup centrée

parent b681421d
......@@ -13,6 +13,29 @@ console.log('Almost Everything Is Asynchronous');
let urlGenre = 'http://localhost:3000/genres';
async function artistSelected(evt) {
try {
let artistID = evt.target.parentElement.id;
let resp = await fetch(`http://localhost:3000/artists/${artistID}/albums`);
if (resp.ok) {
let aside = document.querySelector('aside');
aside.style.visiblity = 'visible';
aside.style.opacity = '1';
aside.style.transition = 'all 1s';
let body = document.querySelector('body');
aside.style.top = `${body.clientHeight/2 - aside.clientHeight/2}px`;
aside.style.left = `${body.clientWidth/2 - aside.clientWidth/2}px`;
console.log(aside);
}
else {
throw new Error('Mauvaise réponse du réseau');
}
}
catch (error) {
console.log('Il y a eu un problème avec l\'opération fetch: ' + error.message);
}
}
async function loadArtists(genre, _contenu) {
// Modification du h2 pour correspondre avec le genre sélectionné
let h2 = document.querySelector('h2');
......@@ -47,12 +70,18 @@ async function loadArtists(genre, _contenu) {
li.appendChild(a);
a.appendChild(h3);
a.setAttribute('href', '#');
a.setAttribute('id',element.id);
h3.innerHTML = element.name;
img.setAttribute('src', element.photo);
img.setAttribute('alt', `picture of ${element.name}`);
li.appendChild(img);
ul.appendChild(li);
console.log(li);
const artist = li.querySelector('a');
console.log(artist);
artist.addEventListener('click', artistSelected);
});
console.log(ul);
}
}
catch (error) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment