Co-authored-by: Matis MAZINGUE <Matis.MAZINGUE@etu.uca.fr> Co-authored-by: clfreville2 <clement.freville2@etu.uca.fr> Reviewed-on: #19 Co-authored-by: Matis MAZINGUE <matis.mazingue@etu.uca.fr> Co-committed-by: Matis MAZINGUE <matis.mazingue@etu.uca.fr>main
parent
beca5f92da
commit
b0507a44ea
@ -0,0 +1,12 @@
|
||||
.no-style {
|
||||
background: none;
|
||||
border: none;
|
||||
padding: 0;
|
||||
font: inherit;
|
||||
color: inherit;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.no-style:focus {
|
||||
outline: none;
|
||||
}
|
@ -0,0 +1,27 @@
|
||||
document.addEventListener('DOMContentLoaded', function() {
|
||||
document.querySelectorAll('.like-toggle').forEach(button => {
|
||||
button.addEventListener('click', function (event) {
|
||||
event.preventDefault();
|
||||
|
||||
let isLiked = this.classList.contains('liked');
|
||||
let url = isLiked ? this.dataset.unlikeUrl : this.dataset.likeUrl;
|
||||
|
||||
fetch(url, { method: 'POST' })
|
||||
.then(response => response.json())
|
||||
.then(data => {
|
||||
if (data.success) {
|
||||
let likesCountElement = this.parentElement.querySelector('.likes-count');
|
||||
likesCountElement.textContent = data.likesCount;
|
||||
this.classList.toggle('liked');
|
||||
this.classList.toggle('not-liked');
|
||||
this.innerHTML = isLiked ? '♡' : '❤️';
|
||||
} else {
|
||||
console.error('Erreur lors du traitement du like/unlike.');
|
||||
}
|
||||
})
|
||||
.catch(error => {
|
||||
console.error('Erreur lors de la requête fetch:', error);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
Loading…
Reference in new issue