parent
6630ec34ee
commit
604e2c16f6
12 changed files with 197 additions and 42 deletions
@ -0,0 +1,69 @@ |
||||
<template> |
||||
<div class="likes" :class="{ 'likes_liked': userLikedProp }"> |
||||
<span>{{ likesProp }}</span><span class="likes__like" @click.prevent="addLike"> |
||||
<svg class="likes__icon icon icon-like"> |
||||
<use v-bind="{'xlink:href': $root.store.staticUrl + 'img/sprite.svg' + '#icon-like' }"></use> |
||||
</svg></span> |
||||
</div> |
||||
</template> |
||||
|
||||
<script> |
||||
import {api} from "../../js/modules/api"; |
||||
|
||||
export default { |
||||
name: 'likes', |
||||
props: ['likes', 'userLiked', 'objType', 'objId'], |
||||
data() { |
||||
return { |
||||
likesProp: +this.likes || 0, |
||||
userLikedProp: this.userLiked || false, |
||||
} |
||||
}, |
||||
methods: { |
||||
addLike() { |
||||
if(this._userLiked){ |
||||
return; |
||||
} |
||||
api.post('/api/v1/likes/', { |
||||
obj_type: this.objType, |
||||
obj_id: this.objId, |
||||
}, { |
||||
headers: { |
||||
'Authorization': `Token ${this.$root.store.accessToken}`, |
||||
} |
||||
}) |
||||
.then((response) => { |
||||
if(response.data && response.data.id) { |
||||
this.userLikedProp = true; |
||||
this.likesProp += 1; |
||||
this.$emit('liked'); |
||||
} |
||||
}) |
||||
} |
||||
} |
||||
} |
||||
</script> |
||||
|
||||
<style> |
||||
.likes { |
||||
font-weight: bold; |
||||
text-align: right; |
||||
} |
||||
|
||||
.likes__like { |
||||
cursor: pointer; |
||||
margin-left: 5px; |
||||
} |
||||
|
||||
.likes_liked .likes__like { |
||||
cursor: default; |
||||
} |
||||
|
||||
.likes__icon { |
||||
margin-bottom: -3px; |
||||
} |
||||
|
||||
.likes_liked .likes__icon { |
||||
fill: #d40700; |
||||
} |
||||
</style> |
||||
Loading…
Reference in new issue