like/dislike
This commit is contained in:
1 parent
4e111f680f
commit
a6feb8449f
5 files changed
+90
-55
No files matched your search
@@ -1,11 +1,11 @@
|
||||
<template>
|
||||
<v-container class="py-1 newsVH px-0 bg-transparent overflow-auto">
|
||||
<my-helper
|
||||
:pretext ="newss"
|
||||
:pretext ="accountStore.user.id"
|
||||
/>
|
||||
<v-card
|
||||
class="mx-auto mb-0 "
|
||||
v-for="(x, i) in newss.newsqueryset" :key= i
|
||||
v-for="(x, i) in newss" :key= i
|
||||
>
|
||||
<v-img
|
||||
:src="`${burl}${x.link}`"
|
||||
@@ -51,11 +51,12 @@
|
||||
<v-col>
|
||||
<v-btn
|
||||
variant="text"
|
||||
icon="mdi-thumb-up-outline"
|
||||
:icon="x.scores.filter(e=> e.user==accountStore.user.id && e.score ==true).length>0?'mdi-thumb-up':'mdi-thumb-up-outline'"
|
||||
color="blue-darken-3"
|
||||
@click="toggleIncrementLike"
|
||||
@click="toggleIncrementLike(x.id, true)"
|
||||
/>
|
||||
{{ incrementLikes }}
|
||||
{{x.scores.filter(e=> e.score==true).length}}
|
||||
<!-- {{ x.likes }} -->
|
||||
</v-col>
|
||||
<v-col class=" ml-8">
|
||||
<v-btn
|
||||
@@ -74,11 +75,13 @@
|
||||
<v-col class="text-center pr-0">
|
||||
<v-btn
|
||||
variant="text"
|
||||
icon="mdi-thumb-down-outline"
|
||||
:icon="x.scores.filter(e=> e.user==accountStore.user.id && e.score == false).length>0?'mdi-thumb-down':'mdi-thumb-down-outline'"
|
||||
color="red-lighten-2"
|
||||
@click="toggleDecrementLike"
|
||||
@click="toggleIncrementLike(x.id, false)"
|
||||
/>
|
||||
{{ derementLikes }}
|
||||
{{x.scores.filter(e=> e.score==false).length}}
|
||||
<!-- {{ x.dislikes }} -->
|
||||
|
||||
</v-col>
|
||||
</v-row>
|
||||
|
||||
@@ -145,6 +148,7 @@ import {useAccountStore} from '@/store/AccountStore'
|
||||
import {getfromserver} from '@/utils/universal_functions'
|
||||
import { baseURL } from '@/utils/axios-api'
|
||||
import myHelper from './UI/my-helper.vue'
|
||||
import { axiosApiInstance } from '@/utils/axios-api'
|
||||
|
||||
const accountStore = useAccountStore()
|
||||
|
||||
@@ -157,38 +161,56 @@ export default {
|
||||
const show=ref(false)
|
||||
const incrementLikes = ref(0)
|
||||
const derementLikes = ref(0)
|
||||
const likes = ref(0)
|
||||
const likedI = ref(false)
|
||||
const likedD = ref(false)
|
||||
const message = ref(0)
|
||||
const commentShow = ref(false)
|
||||
const dialogCommentShow = ref(false)
|
||||
|
||||
const toggleIncrementLike = () => {
|
||||
if (likedI.value) {
|
||||
incrementLikes.value--
|
||||
}
|
||||
else {
|
||||
incrementLikes.value++
|
||||
if(likedD.value){
|
||||
derementLikes.value--
|
||||
likedD.value = false
|
||||
}
|
||||
}
|
||||
likedI.value=!likedI.value
|
||||
const toggleIncrementLike = (news, scores) => {
|
||||
console.log(news, scores);
|
||||
|
||||
// let k = scores.find(e=>e.user==accountStore.user.id)
|
||||
// // if (!k.score){
|
||||
// console.log(k,'=============');
|
||||
// // }
|
||||
|
||||
// if (likedI.value) {
|
||||
// incrementLikes.value--
|
||||
// }
|
||||
// else {
|
||||
// incrementLikes.value++
|
||||
// if(likedD.value){
|
||||
// derementLikes.value--
|
||||
// likedD.value = false
|
||||
// }
|
||||
// }
|
||||
// likedI.value=!likedI.value
|
||||
// likes.value = incrementLikes.value
|
||||
// console.log(incrementLikes.value, 'incrementLikes.value');
|
||||
axiosApiInstance.post(`api/navigation/news/`, {news: news, scores: scores}).then(result => {
|
||||
|
||||
newss.value[newss.value.findIndex(e=> e.id==news)].scores= result.data
|
||||
|
||||
})
|
||||
}
|
||||
|
||||
const toggleDecrementLike = () => {
|
||||
if (likedD.value) {
|
||||
derementLikes.value--
|
||||
}
|
||||
else {
|
||||
derementLikes.value++
|
||||
if(likedI.value){
|
||||
incrementLikes.value--
|
||||
likedI.value = false
|
||||
}
|
||||
}
|
||||
likedD.value=!likedD.value
|
||||
const toggleDecrementLike = (idnews) => {
|
||||
// if (likedD.value) {
|
||||
// derementLikes.value--
|
||||
// }
|
||||
// else {
|
||||
// derementLikes.value++
|
||||
// if(likedI.value){
|
||||
// incrementLikes.value--
|
||||
// likedI.value = false
|
||||
// }
|
||||
// }
|
||||
// likedD.value=!likedD.value
|
||||
// likes.value = derementLikes.value
|
||||
// console.log(derementLikes.value, 'derementLikes.value');
|
||||
// axiosApiInstance.post(`api/navigation/news/`, {like: likes.value, idnews: idnews})
|
||||
}
|
||||
|
||||
const burl = baseURL.slice(0,-1)
|
||||
@@ -207,6 +229,14 @@ export default {
|
||||
}
|
||||
}, {deep:true})
|
||||
|
||||
|
||||
// watch(()=>likes,(newValue,oldValue)=>{
|
||||
// if(newValue){
|
||||
// getfromserver("api/navigation/news/",newss)
|
||||
// }
|
||||
// }, {deep:true})
|
||||
|
||||
|
||||
const commentadd = () => {
|
||||
dialogCommentShow.value=!dialogCommentShow.value
|
||||
// commentShow.value =!commentShow.value
|
||||
@@ -225,7 +255,8 @@ export default {
|
||||
toggleIncrementLike,
|
||||
toggleDecrementLike,
|
||||
dialogCommentShow,
|
||||
commentadd
|
||||
commentadd,
|
||||
accountStore
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,7 +32,7 @@
|
||||
|
||||
|
||||
|
||||
|
||||
<!-- {{appStore.countvisitor}} -->
|
||||
|
||||
</v-card>
|
||||
</v-col>
|
||||
|
||||
Reference in new issue
Block a user