File size: 611 Bytes
f710fc8 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
function likePost(postId) {
fetch(`/like_post/${postId}`, { method: 'POST' })
.then((response) => response.json())
.then((data) => {
const likeCountSpan = document.getElementById(`likeCount${postId}`);
likeCountSpan.textContent = data.likes_count;
const heartIcon = document.getElementById(`heartIcon${postId}`);
if (data.liked) {
heartIcon.classList.add('liked');
heartIcon.classList.remove('heartIcon');
} else {
heartIcon.classList.remove('liked');
heartIcon.classList.add('heartIcon');
}
});
} |