1
0
Fork 1
mirror of https://github.com/pixelfed/pixelfed.git synced 2024-12-25 01:05:36 +00:00

Remove likebutton.js

This commit is contained in:
Daniel Supernault 2019-02-10 21:19:18 -07:00
parent e25ff8406c
commit efc5db1f52
No known key found for this signature in database
GPG key ID: 0DEF1C662C9033F7

View file

@ -1,75 +0,0 @@
$(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);
})
}
pixelfed.hydrateLikes = () => {
var likes = ls.get('likes');
$('.like-form').each(function(i, el) {
var el = $(el);
var id = el.data('id');
var heart = el.find('.status-heart');
if(likes.indexOf(id) != -1) {
heart.removeClass('far text-dark').addClass('fas text-danger');
} else {
heart.removeClass('fas text-danger').addClass('far text-dark');
}
});
};
pixelfed.fetchLikes();
pixelfed.hydrateLikes();
$(document).on('submit', '.like-form', function(e) {
e.preventDefault();
var el = $(this);
var id = el.data('id');
axios.post('/i/like', {item: id})
.then(function (res) {
pixelfed.fetchLikes();
pixelfed.hydrateLikes();
var likes = ls.get('likes');
var action = false;
var counter = el.parents().eq(1).find('.like-count');
var count = res.data.count;
var heart = el.find('.status-heart');
if(likes.indexOf(id) > -1) {
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('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');
});
});
});