mirror of
https://github.com/bs-community/blessing-skin-server.git
synced 2025-03-07 15:16:40 +08:00
Add likes count to items on skinlib page
This commit is contained in:
parent
d30f049111
commit
1c2e3a19ca
@ -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;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
@ -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
|
||||
},
|
||||
|
@ -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);
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user