1
0
Fork 1
mirror of https://github.com/pixelfed/pixelfed.git synced 2024-12-24 00:35:59 +00:00

Update likebutton.js

This commit is contained in:
Daniel Supernault 2018-11-10 20:56:19 -07:00
parent 7e559f9504
commit 329956b60b
No known key found for this signature in database
GPG key ID: 0DEF1C662C9033F7

View file

@ -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');
});
});