From e82a1b5ce8429acbe8adb9a4241b5e1f6dfaf64d Mon Sep 17 00:00:00 2001 From: Bangara Raju Kottedi Date: Thu, 24 Aug 2023 22:07:07 +0530 Subject: [PATCH 1/3] code refactoring --- assets/js/likes.js | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/assets/js/likes.js b/assets/js/likes.js index 907a8f7..3803deb 100644 --- a/assets/js/likes.js +++ b/assets/js/likes.js @@ -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"); }); \ No newline at end of file From 07c4796861a84fc5dbb11823194c2f1a0001d554 Mon Sep 17 00:00:00 2001 From: Bangara Raju Kottedi Date: Fri, 25 Aug 2023 14:17:38 +0530 Subject: [PATCH 2/3] post likes icon flickering issue resolved --- _includes/head.html | 4 ++++ _includes/likes.html | 1 - 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/_includes/head.html b/_includes/head.html index ad7f878..ac1e8fc 100644 --- a/_includes/head.html +++ b/_includes/head.html @@ -85,6 +85,10 @@ {% endif %} + + + + diff --git a/_includes/likes.html b/_includes/likes.html index 4f52229..fffcad3 100644 --- a/_includes/likes.html +++ b/_includes/likes.html @@ -1,4 +1,3 @@ - {% include loader.html id="likes-loader" %} From 5baad750f4f2d887bf3fbabdbffc8d5cc1d7fb7f Mon Sep 17 00:00:00 2001 From: Bangara Raju Kottedi Date: Fri, 25 Aug 2023 14:21:12 +0530 Subject: [PATCH 3/3] revert post likes ui changes - there is no change --- _includes/head.html | 4 ---- _includes/likes.html | 1 + 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/_includes/head.html b/_includes/head.html index ac1e8fc..ad7f878 100644 --- a/_includes/head.html +++ b/_includes/head.html @@ -85,10 +85,6 @@ {% endif %} - - - - diff --git a/_includes/likes.html b/_includes/likes.html index fffcad3..4f52229 100644 --- a/_includes/likes.html +++ b/_includes/likes.html @@ -1,3 +1,4 @@ + {% include loader.html id="likes-loader" %}