mirror of
https://github.com/pixelfed/pixelfed.git
synced 2024-12-24 14:03:16 +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() {
|
$(document).ready(function() {
|
||||||
|
|
||||||
pixelfed.fetchLikes = () => {
|
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')
|
axios.get('/api/v1/likes')
|
||||||
.then(function (res) {
|
.then(function (res) {
|
||||||
ls.set('likes', res.data);
|
ls.set('likes', res.data);
|
||||||
|
ls.set('likesUpdated', ts);
|
||||||
})
|
})
|
||||||
.catch(function (res) {
|
.catch(function (res) {
|
||||||
ls.set('likes', []);
|
ls.set('likes', []);
|
||||||
|
ls.set('likesUpdated', ts);
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -19,9 +29,9 @@ $(document).ready(function() {
|
||||||
var heart = el.find('.status-heart');
|
var heart = el.find('.status-heart');
|
||||||
|
|
||||||
if(likes.indexOf(id) != -1) {
|
if(likes.indexOf(id) != -1) {
|
||||||
heart.removeClass('text-dark').addClass('text-primary');
|
heart.removeClass('far text-dark').addClass('fas text-danger');
|
||||||
} else {
|
} 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');
|
var heart = el.find('.status-heart');
|
||||||
|
|
||||||
if(likes.indexOf(id) > -1) {
|
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) {
|
likes = likes.filter(function(item) {
|
||||||
return item !== id
|
return item !== id
|
||||||
});
|
});
|
||||||
counter.text(count);
|
counter.text(count);
|
||||||
action = 'unlike';
|
action = 'unlike';
|
||||||
} else {
|
} else {
|
||||||
heart.removeClass('text-dark').addClass('text-primary');
|
heart.removeClass('far text-dark').addClass('fas text-danger');
|
||||||
likes.push(id);
|
likes.push(id);
|
||||||
counter.text(count);
|
counter.text(count);
|
||||||
action = 'like';
|
action = 'like';
|
||||||
}
|
}
|
||||||
|
|
||||||
ls.set('likes', likes);
|
ls.set('likes', likes);
|
||||||
|
ls.set('likesUpdated', Date.now());
|
||||||
console.log(action + ' - ' + id + ' like event');
|
console.log(action + ' - ' + id + ' like event');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue