code refactoring
This commit is contained in:
parent
59fda443de
commit
e82a1b5ce8
@ -6,10 +6,20 @@ likesLoader.style.display = "none"
|
||||
|
||||
let likesAmount = likesCount.innerHTML;
|
||||
|
||||
function apiCall(url) {
|
||||
function onLoadAndClick(){
|
||||
likesLoader.style.display = "inline-flex"
|
||||
likesCount.style.display = "none";
|
||||
heartIcon.style.pointerEvents = 'none';
|
||||
}
|
||||
|
||||
function apiCall(url, event) {
|
||||
onLoadAndClick();
|
||||
ajax(url)
|
||||
.then(function (result) {
|
||||
console.log(result);
|
||||
if(event === "click"){
|
||||
heartIcon.classList.toggle("liked");
|
||||
}
|
||||
likesCount.innerHTML = result;
|
||||
likesLoader.style.display = "none"
|
||||
likesCount.style.display = "inline-flex";
|
||||
@ -17,7 +27,7 @@ function apiCall(url) {
|
||||
})
|
||||
.catch(function () {
|
||||
likesLoader.style.display = "none";
|
||||
likesCount.style.display = "inline-block";
|
||||
likesCount.style.display = "inline-flex";
|
||||
});
|
||||
}
|
||||
|
||||
@ -26,16 +36,11 @@ var apiUrl = serviceUrl + "/GetPostLikes?siteId=" + siteId + "&postId=" + postId
|
||||
apiCall(apiUrl);
|
||||
|
||||
heartIcon.addEventListener("click", () => {
|
||||
likesLoader.style.display = "inline-flex"
|
||||
likesCount.style.display = "none";
|
||||
heartIcon.style.pointerEvents = 'none';
|
||||
|
||||
heartIcon.classList.toggle("liked");
|
||||
if (heartIcon.classList.contains("liked")) {
|
||||
if (!heartIcon.classList.contains("liked")) {
|
||||
apiUrl = serviceUrl + "/LikePost?siteId=" + siteId + "&postId=" + postId;
|
||||
} else {
|
||||
apiUrl = serviceUrl + "/DislikePost?siteId=" + siteId + "&postId=" + postId;
|
||||
}
|
||||
|
||||
apiCall(apiUrl);
|
||||
apiCall(apiUrl, "click");
|
||||
});
|
||||
Loading…
Reference in New Issue
Block a user