mirror of
https://github.com/pixelfed/pixelfed.git
synced 2024-12-24 16:53:17 +00:00
Update likebutton.js
This commit is contained in:
parent
7e559f9504
commit
329956b60b
1 changed files with 15 additions and 4 deletions
19
resources/assets/js/components/likebutton.js
vendored
19
resources/assets/js/components/likebutton.js
vendored
|
@ -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');
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue