feat: count nested replies

This commit is contained in:
Tim
2025-08-03 01:15:14 +08:00
parent 2ad3275753
commit 06eb9e2c7e
2 changed files with 11 additions and 6 deletions

View File

@@ -35,10 +35,10 @@
<div class="comment-editor-wrapper">
<CommentEditor v-if="showEditor" @submit="submitReply" :loading="isWaitingForReply" :disabled="!loggedIn" :show-login-overlay="!loggedIn" />
</div>
<div v-if="comment.reply && comment.reply.length" class="reply-toggle" @click="toggleReplies">
<div v-if="replyCount" class="reply-toggle" @click="toggleReplies">
<i v-if="showReplies" class="fas fa-chevron-up reply-toggle-icon"></i>
<i v-else class="fas fa-chevron-down reply-toggle-icon"></i>
{{ comment.reply.length }}条回复
{{ replyCount }}条回复
</div>
<div v-if="showReplies" class="reply-list">
<BaseTimeline :items="comment.reply">
@@ -110,6 +110,8 @@ const CommentItem = {
const lightboxIndex = ref(0)
const lightboxImgs = ref([])
const loggedIn = computed(() => authState.loggedIn)
const countReplies = (list) => list.reduce((sum, r) => sum + 1 + countReplies(r.reply || []), 0)
const replyCount = computed(() => countReplies(props.comment.reply || []))
const toggleReplies = () => {
showReplies.value = !showReplies.value
}
@@ -206,7 +208,7 @@ const CommentItem = {
lightboxVisible.value = true
}
}
return { showReplies, toggleReplies, showEditor, toggleEditor, submitReply, copyCommentLink, renderMarkdown, isWaitingForReply, commentMenuItems, deleteComment, lightboxVisible, lightboxIndex, lightboxImgs, handleContentClick, loggedIn }
return { showReplies, toggleReplies, showEditor, toggleEditor, submitReply, copyCommentLink, renderMarkdown, isWaitingForReply, commentMenuItems, deleteComment, lightboxVisible, lightboxIndex, lightboxImgs, handleContentClick, loggedIn, replyCount }
}
}

View File

@@ -165,6 +165,9 @@ export default {
const pageSize = 10
const allLoaded = ref(false)
const countComments = (list) =>
list.reduce((sum, c) => sum + 1 + countComments(c.replies || []), 0)
const loadOptions = async () => {
if (selectedCategory.value && !isNaN(selectedCategory.value)) {
try {
@@ -254,7 +257,7 @@ export default {
category: p.category,
tags: p.tags || [],
members: (p.participants || []).map(m => ({ id: m.id, avatar: m.avatar })),
comments: (p.comments || []).length,
comments: countComments(p.comments || []),
views: p.views,
time: TimeManager.format(p.createdAt),
pinned: !!p.pinnedAt
@@ -291,7 +294,7 @@ export default {
category: p.category,
tags: p.tags || [],
members: (p.participants || []).map(m => ({ id: m.id, avatar: m.avatar })),
comments: (p.comments || []).length,
comments: countComments(p.comments || []),
views: p.views,
time: TimeManager.format(p.createdAt),
pinned: !!p.pinnedAt
@@ -328,7 +331,7 @@ export default {
category: p.category,
tags: p.tags || [],
members: (p.participants || []).map(m => ({ id: m.id, avatar: m.avatar })),
comments: (p.comments || []).length,
comments: countComments(p.comments || []),
views: p.views,
time: TimeManager.format(p.lastReplyAt || p.createdAt),
pinned: !!p.pinnedAt