add comment upvote feature support (30%)

pull/275/head
Michael Li 2 years ago
parent 08e5a3f695
commit 30749adb11
No known key found for this signature in database

@ -24,12 +24,13 @@
<template #header-extra> <template #header-extra>
<div class="opt-wrap"> <div class="opt-wrap">
<span class="timestamp"> <span class="timestamp">
{{ {{ comment.ip_loc}}
<!-- {{
comment.ip_loc comment.ip_loc
? comment.ip_loc + ' · ' ? comment.ip_loc + ' · '
: comment.ip_loc : comment.ip_loc
}} }}
{{ formatPrettyTime(comment.created_on, store.state.collapsedLeft) }} {{ formatPrettyTime(comment.created_on, store.state.collapsedLeft) }} -->
</span> </span>
<n-popconfirm <n-popconfirm
@ -74,6 +75,16 @@
<post-image <post-image
v-if="comment.imgs.length > 0" v-if="comment.imgs.length > 0"
:imgs="comment.imgs" /> :imgs="comment.imgs" />
<!-- -->
<compose-reply
ref="replyComposeRef"
:timestamp="comment.created_on"
:comment-id="comment.id"
:at-userid="replyAtUserID"
:at-username="replyAtUsername"
@reload="reload"
@reset="resetReply"
/>
<!-- --> <!-- -->
<div class="reply-wrap"> <div class="reply-wrap">
<reply-item <reply-item
@ -84,16 +95,6 @@
@reload="reload" @reload="reload"
/> />
</div> </div>
<!-- -->
<compose-reply
ref="replyComposeRef"
v-if="store.state.userInfo.id > 0"
:comment-id="comment.id"
:at-userid="replyAtUserID"
:at-username="replyAtUsername"
@reload="reload"
@reset="resetReply"
/>
</template> </template>
</n-thing> </n-thing>
</div> </div>

@ -1,10 +1,32 @@
<template> <template>
<div class="reply-compose-wrap"> <div class="reply-compose-wrap">
<div class="reply-switch"> <div class="reply-switch">
<span class="show" v-if="!showReply" @click="switchReply(true)"> <span class="time-item">
{{ formatPrettyTime(timestamp, store.state.collapsedLeft) }}
</span>
<div
class="action-item hover"
@click.stop=""
>
<n-icon size="medium">
<thumb-up-outlined v-if="!hasUpvote" />
<thumb-up-twotone v-if="hasUpvote" color="#18a058" />
</n-icon>
<span class="upvote-count">1000</span>
</div>
<div
class="action-item hover"
@click.stop=""
>
<n-icon size="medium">
<thumb-down-outlined v-if="!hasDownvote" />
<thumb-down-twotone v-if="hasDownvote" color="#18a058" />
</n-icon>
</div>
<span class="show" v-if="store.state.userLogined && !showReply" @click="switchReply(true)">
</span> </span>
<span class="hide" v-if="showReply" @click="switchReply(false)"> <span class="hide" v-if="store.state.userLogined && showReply" @click="switchReply(false)">
</span> </span>
</div> </div>
@ -40,18 +62,31 @@
<script setup lang="ts"> <script setup lang="ts">
import { ref } from 'vue'; import { ref } from 'vue';
import { useStore } from 'vuex';
import { formatPrettyTime } from '@/utils/formatTime';
import { createCommentReply } from '@/api/post'; import { createCommentReply } from '@/api/post';
import { InputInst } from 'naive-ui'; import { InputInst } from 'naive-ui';
import {
ThumbUpTwotone,
ThumbUpOutlined,
ThumbDownTwotone,
ThumbDownOutlined,
} from '@vicons/material';
const hasUpvote = ref(false)
const hasDownvote = ref(true)
const props = withDefaults(defineProps<{ const props = withDefaults(defineProps<{
timestamp: number,
commentId: number, commentId: number,
atUserid: number, atUserid: number,
atUsername: string, atUsername: string,
}>(), { }>(), {
timestamp: 0,
commentId: 0, commentId: 0,
atUserid: 0, atUserid: 0,
atUsername: '' atUsername: ''
}); });
const store = useStore();
const emit = defineEmits<{ const emit = defineEmits<{
(e: 'reload'): void, (e: 'reload'): void,
(e: 'reset'): void (e: 'reset'): void
@ -95,10 +130,29 @@ defineExpose({ switchReply });
<style lang="less" scoped> <style lang="less" scoped>
.reply-compose-wrap { .reply-compose-wrap {
.reply-switch { .reply-switch {
display: flex;
align-items: center;
text-align: right; text-align: right;
font-size: 12px; font-size: 12px;
margin: 10px 0; margin: 10px 0;
.time-item {
font-size: 12px;
opacity: 0.75;
margin-right: 18px;
}
.action-item {
display: flex;
align-items: center;
margin-right: 18px;
opacity: 0.75;
.upvote-count {
margin-left: 4px;
font-size: 12px;
}
&.hover {
cursor: pointer;
}
}
.show { .show {
color: #18a058; color: #18a058;
cursor: pointer; cursor: pointer;

@ -27,12 +27,13 @@
</router-link> </router-link>
</div> </div>
<div class="timestamp"> <div class="timestamp">
{{ {{ props.reply.ip_loc }}
<!-- {{
props.reply.ip_loc props.reply.ip_loc
? props.reply.ip_loc + ' · ' ? props.reply.ip_loc + ' · '
: props.reply.ip_loc : props.reply.ip_loc
}} }} -->
{{ formatPrettyTime(props.reply.created_on, store.state.collapsedLeft) }} <!-- {{ formatPrettyTime(props.reply.created_on, store.state.collapsedLeft) }} -->
<n-popconfirm <n-popconfirm
v-if=" v-if="
store.state.userInfo.is_admin || store.state.userInfo.is_admin ||
@ -58,18 +59,50 @@
<div class="base-wrap"> <div class="base-wrap">
<div class="content">{{ props.reply.content }}</div> <div class="content">{{ props.reply.content }}</div>
<div class="reply-switch" v-if="store.state.userInfo.id > 0"> <div class="reply-switch">
<span class="show" @click="focusReply"> </span> <span class="time-item">
{{ formatPrettyTime(props.reply.created_on, store.state.collapsedLeft) }}
</span>
<div
class="action-item hover"
@click.stop=""
>
<n-icon size="medium">
<thumb-up-outlined v-if="!hasUpvote" />
<thumb-up-twotone v-if="hasUpvote" color="#18a058" />
</n-icon>
<span class="upvote-count">100</span>
</div>
<div
class="action-item hover"
@click.stop=""
>
<n-icon size="medium">
<thumb-down-outlined v-if="!hasDownvote" />
<thumb-down-twotone v-if="hasDownvote" color="#18a058" />
</n-icon>
</div>
<span v-if="store.state.userLogined" class="show" @click="focusReply"> </span>
</div> </div>
</div> </div>
</div> </div>
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
import { ref } from 'vue';
import { useStore } from 'vuex'; import { useStore } from 'vuex';
import { Trash } from '@vicons/tabler'; import { Trash } from '@vicons/tabler';
import { formatPrettyTime } from '@/utils/formatTime'; import { formatPrettyTime } from '@/utils/formatTime';
import { deleteCommentReply } from '@/api/post'; import { deleteCommentReply } from '@/api/post';
import {
ThumbUpTwotone,
ThumbUpOutlined,
ThumbDownTwotone,
ThumbDownOutlined,
} from '@vicons/material';
const hasUpvote = ref(true)
const hasDownvote = ref(false)
const props = withDefaults(defineProps<{ const props = withDefaults(defineProps<{
reply: Item.ReplyProps, reply: Item.ReplyProps,
@ -135,7 +168,7 @@ const execDelAction = () => {
} }
} }
.base-wrap { .base-wrap {
display: flex; display: block;
.content { .content {
width: calc(100% - 40px); width: calc(100% - 40px);
margin-top: 4px; margin-top: 4px;
@ -144,11 +177,28 @@ const execDelAction = () => {
line-height: 2; line-height: 2;
} }
.reply-switch { .reply-switch {
width: 40px; display: flex;
text-align: right; align-items: center;
font-size: 12px; font-size: 12px;
margin: 10px 0 0; margin: 10px 0 0;
.time-item {
font-size: 12px;
opacity: 0.75;
margin-right: 18px;
}
.action-item {
display: flex;
align-items: center;
margin-right: 18px;
opacity: 0.75;
.upvote-count {
margin-left: 4px;
font-size: 12px;
}
&.hover {
cursor: pointer;
}
}
.show { .show {
color: #18a058; color: #18a058;
cursor: pointer; cursor: pointer;

Loading…
Cancel
Save