Add likes count to items on skinlib page
This commit is contained in:
parent
3adf04ff6d
commit
4f5c2ffa98
|
|
@ -559,8 +559,9 @@ describe('tests for "operations" module', () => {
|
|||
window.trans = jest.fn(key => key);
|
||||
document.body.innerHTML = `
|
||||
<div id="likes">5</div>
|
||||
<a tid="1"></a>
|
||||
<a id="1"></a>
|
||||
<a id="quick-apply" style="display: none;"></a>
|
||||
<a class="like" tid="1"></a>
|
||||
<a class="btn" id="1"></a>
|
||||
`;
|
||||
const updateTextureStatus = require(modulePath).updateTextureStatus;
|
||||
|
||||
|
|
@ -571,6 +572,7 @@ describe('tests for "operations" module', () => {
|
|||
expect($('#1').attr('onclick')).toBe('removeFromCloset(1);');
|
||||
expect($('#1').html()).toBe('skinlib.removeFromCloset');
|
||||
expect($('div').html()).toBe('6');
|
||||
expect($('#quick-apply').css('display')).not.toBe('none');
|
||||
|
||||
updateTextureStatus(1, 'remove');
|
||||
expect($('a[tid=1]').attr('onclick')).toBe('addToCloset(1);');
|
||||
|
|
@ -579,6 +581,7 @@ describe('tests for "operations" module', () => {
|
|||
expect($('#1').attr('onclick')).toBe('addToCloset(1);');
|
||||
expect($('#1').html()).toBe('skinlib.addToCloset');
|
||||
expect($('div').html()).toBe('5');
|
||||
expect($('#quick-apply').css('display')).toBe('none');
|
||||
});
|
||||
|
||||
it('click changing privacy button', async () => {
|
||||
|
|
|
|||
|
|
@ -107,7 +107,8 @@ function renderSkinlibItemComponent(item) {
|
|||
|
||||
item.name = $.fn.dataTable.render.text().filter(item.name);
|
||||
|
||||
return `<a href="${ url('skinlib/show/' + item.tid) }">
|
||||
return `
|
||||
<a href="${ url('skinlib/show/' + item.tid) }">
|
||||
<div class="item" tid="${ item.tid }">
|
||||
<div class="item-body">
|
||||
<img src="${ url('preview/' + item.tid + '.png') }">
|
||||
|
|
@ -120,6 +121,7 @@ function renderSkinlibItemComponent(item) {
|
|||
</span>
|
||||
</p>
|
||||
|
||||
<span class="pull-right likes-count">${ item.likes }</span>
|
||||
<a title="${title}" class="more like ${liked} ${anonymous}" tid="${ item.tid }" href="javascript:;" data-placement="top" data-toggle="tooltip"><i class="fa fa-heart"></i></a>
|
||||
|
||||
<small class="more private-label ${(item.public === 0) ? '' : 'hide'}" tid="${ item.tid }">
|
||||
|
|
|
|||
|
|
@ -180,17 +180,21 @@ async function changeTextureModel(tid, oldModel) {
|
|||
* @return {null}
|
||||
*/
|
||||
function updateTextureStatus(tid, action) {
|
||||
const likes = parseInt($('#likes').html()) + (action === 'add' ? 1 : -1);
|
||||
const likesCounter = $('#likes').length ? $('#likes') : $(`.item[tid=${tid}] .likes-count`);
|
||||
const likes = parseInt(likesCounter.html()) + (action === 'add' ? 1 : -1);
|
||||
const buttonAction = (action === 'add') ? 'removeFromCloset' : 'addToCloset';
|
||||
likesCounter.html(likes);
|
||||
|
||||
$(`a[tid=${tid}]`)
|
||||
// On "skinlib" page
|
||||
$(`a.like[tid=${tid}]`)
|
||||
.attr('onclick', `${buttonAction}(${tid});`)
|
||||
.attr('title', trans(`skinlib.${buttonAction}`))
|
||||
.toggleClass('liked');
|
||||
$(`#${tid}`)
|
||||
|
||||
// On "skinlib/show" page
|
||||
$(`.btn#${tid}`)
|
||||
.attr('onclick', `${buttonAction}(${tid});`)
|
||||
.html(trans(`skinlib.${buttonAction}`));
|
||||
$('#likes').html(likes);
|
||||
$('#quick-apply').toggle(action === 'add');
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user