From 329956b60b017f5aba1c32bd34c441a18f2320b2 Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Sat, 10 Nov 2018 20:56:19 -0700 Subject: [PATCH] Update likebutton.js --- resources/assets/js/components/likebutton.js | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/resources/assets/js/components/likebutton.js b/resources/assets/js/components/likebutton.js index 9e7206445..7888f220e 100644 --- a/resources/assets/js/components/likebutton.js +++ b/resources/assets/js/components/likebutton.js @@ -1,12 +1,22 @@ $(document).ready(function() { pixelfed.fetchLikes = () => { + let ts = Date.now(); + let offset = ts - 900000; + let updated = ls.get('likesUpdated'); + + if(updated != null && ls.get('likes').length > 0 || offset < updated) { + return; + } + axios.get('/api/v1/likes') .then(function (res) { ls.set('likes', res.data); + ls.set('likesUpdated', ts); }) .catch(function (res) { ls.set('likes', []); + ls.set('likesUpdated', ts); }) } @@ -19,9 +29,9 @@ $(document).ready(function() { var heart = el.find('.status-heart'); if(likes.indexOf(id) != -1) { - heart.removeClass('text-dark').addClass('text-primary'); + heart.removeClass('far text-dark').addClass('fas text-danger'); } else { - heart.removeClass('text-primary').addClass('text-dark'); + heart.removeClass('fas text-danger').addClass('far text-dark'); } }); }; @@ -44,20 +54,21 @@ $(document).ready(function() { var heart = el.find('.status-heart'); if(likes.indexOf(id) > -1) { - heart.removeClass('text-primary').addClass('text-dark'); + heart.removeClass('fas text-danger').addClass('far text-dark'); likes = likes.filter(function(item) { return item !== id }); counter.text(count); action = 'unlike'; } else { - heart.removeClass('text-dark').addClass('text-primary'); + heart.removeClass('far text-dark').addClass('fas text-danger'); likes.push(id); counter.text(count); action = 'like'; } ls.set('likes', likes); + ls.set('likesUpdated', Date.now()); console.log(action + ' - ' + id + ' like event'); }); });