feat: dislike topic

This commit is contained in:
KUN1007 2023-10-04 22:35:25 +08:00
parent b4dddd7c11
commit d3e45850ce
5 changed files with 109 additions and 24 deletions

View file

@ -79,6 +79,18 @@ export async function updateTopicLikeApi(
return response
}
// 点踩话题
export async function updateTopicDislikeApi(
request: Action.TopicDislikeTopicRequestData
): Promise<Action.TopicDislikeTopicResponseData> {
const queryParams = objectToQueryParams(request, 'tid')
const url = `/topics/${request.tid}/dislike?${queryParams}`
const response = fetchPut<Action.TopicDislikeTopicResponseData>(url)
return response
}
// 根据话题 tid 获取话题回复
export async function getRepliesByPidApi(
request: Topic.TopicReplyRequestData

View file

@ -15,8 +15,18 @@ export interface TopicLikeTopicRequestData {
isPush: boolean
}
// 点踩
export interface TopicDislikeTopicRequestData {
tid: number
to_uid: number
isPush: boolean
}
// 推话题响应数据的格式
export type TopicUpvoteTopicResponseData = KUNGalgameResponseData<{}>
// 点赞话题响应数据的格式
export type TopicLikeTopicResponseData = KUNGalgameResponseData<{}>
// 点踩话题响应数据的格式
export type TopicDislikeTopicResponseData = KUNGalgameResponseData<{}>

View file

@ -19,6 +19,9 @@ import {
updateTopicLikeApi,
TopicLikeTopicRequestData,
TopicLikeTopicResponseData,
updateTopicDislikeApi,
TopicDislikeTopicRequestData,
TopicDislikeTopicResponseData,
} from '@/api'
// 回复
@ -136,8 +139,22 @@ export const useKUNGalgameTopicStore = defineStore({
return await updateTopicLikeApi(requestData)
},
// 点踩话题
async updateTopicDislike(
tid: number,
toUid: number,
isPush: boolean
): Promise<TopicDislikeTopicResponseData> {
const requestData: TopicDislikeTopicRequestData = {
tid: tid,
to_uid: toUid,
isPush: isPush,
}
return await updateTopicDislikeApi(requestData)
},
// 获取回复
async getReplies(tid: number): Promise<TopicReplyResponseData> {
async getReplies(tid: number): Promise<TopicDislikeTopicResponseData> {
// 这里的默认值用于初始化
const requestData: TopicReplyRequestData = {
tid: tid,

View file

@ -102,7 +102,7 @@ const loliStatus = computed(() => {
<Rewrite v-if="edited" :time="edited" />
</div>
</div>
<!-- 话题的点赞数等信息楼主的 floor 就是 0被作用人就是该话题的发布人 -->
<!-- 话题的点赞数等信息被作用人就是该话题的发布人 -->
<MasterFooter
:info="{
tid,
@ -111,7 +111,6 @@ const loliStatus = computed(() => {
dislikes,
upvotes,
share,
to_floor: 0,
}"
:topic="{ tid, title, content, tags, category }"
:master="user"

View file

@ -36,8 +36,6 @@ const props = defineProps<{
dislikes: number[]
upvotes: number[]
share: number[]
// floor
to_floor: number
}
topic: {
tid: number
@ -56,8 +54,10 @@ const props = defineProps<{
*/
// uid
const currUserUid = useKUNGalgameUserStore().uid
// uid
const masterUid = props.master.uid
//
const isShowRewrite = currUserUid === props.master.uid
const isShowRewrite = currUserUid === masterUid
// footer
const actions = reactive({
@ -75,11 +75,20 @@ const isActive = reactive({
isShared: false,
})
// throttle
const throttleCallback = () => {
message(
'You can only perform one operation within 1007 milliseconds',
'您在 1007 毫秒内只能进行一次操作',
'warn'
)
}
// throttle 1007
const handleClickLikeThrottled = throttle(
async () => {
//
if (currUserUid === props.master.uid) {
if (currUserUid === masterUid) {
message(
'You cannot like your own topic',
'您不可以给自己的话题点赞',
@ -93,7 +102,7 @@ const handleClickLikeThrottled = throttle(
const res = await useKUNGalgameTopicStore().updateTopicLike(
props.info.tid,
props.master.uid,
masterUid,
isActive.isLiked
)
@ -107,19 +116,45 @@ const handleClickLikeThrottled = throttle(
}
},
1007,
() => {
throttleCallback
)
// throttle 1007
const handleClickDislikeThrottled = throttle(
async () => {
if (currUserUid === masterUid) {
message(
'You can only perform one operation within 1007 milliseconds',
'您在 1007 毫秒内只能进行一次操作',
'You cannot dislike your own topic',
'您不可以给自己的话题点踩',
'warn'
)
return
}
isActive.isDisliked = !isActive.isDisliked
const res = await useKUNGalgameTopicStore().updateTopicDislike(
props.info.tid,
masterUid,
isActive.isDisliked
)
if (res.code === 200) {
//
actions.dislikes.length = isActive.isDisliked
? actions.dislikes.length + 1
: actions.dislikes.length - 1
} else {
message('Topic dislike failed!', '点踩话题失败', 'error')
}
},
1007,
throttleCallback
)
//
const handleClickUpvote = async () => {
//
if (currUserUid === props.master.uid) {
if (currUserUid === masterUid) {
message('You cannot upvote your own topic', '您不可以推自己的话题', 'warn')
return
}
@ -145,7 +180,7 @@ const handleClickUpvote = async () => {
//
const res = await useKUNGalgameTopicStore().updateTopicUpvote(
props.info.tid,
props.master.uid
masterUid
)
if (res.code === 200) {
@ -164,19 +199,25 @@ const handleClickLike = () => {
handleClickLikeThrottled()
}
//
const handleClickDislike = () => {
handleClickDislikeThrottled()
}
//
const handelReply = async () => {
const handleClickReply = async () => {
// 便
replyDraft.value.tid = props.info.tid
// uid
replyDraft.value.to_uid = props.master.uid
replyDraft.value.to_floor = props.info.to_floor
replyDraft.value.to_uid = masterUid
// floor 0
replyDraft.value.to_floor = 0
//
isEdit.value = true
}
//
const handleClickEdit = () => {
const handleClickRewrite = () => {
//
topicRewrite.value.tid = props.topic.tid
topicRewrite.value.title = props.topic.title
@ -250,7 +291,13 @@ onMounted(() => {
</li>
<!-- -->
<li>
<span class="icon"><Icon icon="line-md:thumbs-down-twotone" /></span>
<span
class="icon"
:class="isActive.isDisliked ? 'active' : ''"
@click="handleClickDislike"
>
<Icon icon="line-md:thumbs-down-twotone" />
</span>
{{ actions.dislikes.length }}
</li>
</ul>
@ -258,7 +305,7 @@ onMounted(() => {
<!-- 底部右侧部分回复评论只看编辑 -->
<div class="right">
<div @click="handelReply" class="reply">
<div @click="handleClickReply" class="reply">
{{ $tm('topic.content.reply') }}
</div>
@ -269,7 +316,7 @@ onMounted(() => {
<span class="icon"><Icon icon="ph:user-focus-duotone" /></span>
<!-- 编辑 -->
<span v-if="isShowRewrite" @click="handleClickEdit" class="icon">
<span v-if="isShowRewrite" @click="handleClickRewrite" class="icon">
<Icon icon="line-md:pencil-twotone-alt" />
</span>
</div>