Add likes count to items on skinlib page

This commit is contained in:
Pig Fang 2018-08-20 23:30:05 +08:00
parent d30f049111
commit 1c2e3a19ca
3 changed files with 13 additions and 2 deletions

View File

@ -113,6 +113,7 @@
:name="item.name"
:type="item.type"
:liked="item.liked"
:likes="item.likes"
:isPublic="item.public"
:anonymous="anonymous"
@like-toggled="onLikeToggled(index, $event)"
@ -244,6 +245,7 @@ export default {
},
onLikeToggled(index, action) {
this.items[index].liked = action;
this.items[index].likes += action ? 1 : -1;
}
}
};

View File

@ -18,7 +18,10 @@
:class="{ liked, anonymous }"
href="#"
@click.stop="toggleLiked"
><i class="fas fa-heart"></i></a>
>
<i class="fas fa-heart"></i>
<span>{{ likes }}</span>
</a>
<small v-if="!isPublic" class="more private-label">
{{ $t('skinlib.private') }}
@ -41,6 +44,7 @@ export default {
validator: value => ['steve', 'alex', 'cape'].includes(value)
},
liked: Boolean,
likes: Number,
anonymous: Boolean,
isPublic: Boolean // `public` is a reserved keyword
},

View File

@ -172,10 +172,15 @@ test('on page changed', () => {
test('on like toggled', async () => {
Vue.prototype.$http.get.mockResolvedValue({
items: [{ tid: 1, liked: false }], total_pages: 1, current_uid: 0
items: [{ tid: 1, liked: false, likes: 0 }], total_pages: 1, current_uid: 0
});
const wrapper = mount(List);
await wrapper.vm.$nextTick();
wrapper.vm.onLikeToggled(0, true);
expect(wrapper.vm.items[0].liked).toBeTrue();
expect(wrapper.vm.items[0].likes).toBe(1);
wrapper.vm.onLikeToggled(0, false);
expect(wrapper.vm.items[0].liked).toBeFalse();
expect(wrapper.vm.items[0].likes).toBe(0);
});