mirror of
https://github.com/nagisa77/OpenIsle.git
synced 2026-06-25 10:15:17 +08:00
feat: 评论排序支持
This commit is contained in:
@@ -73,21 +73,16 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="comments-container">
|
<div v-if="isFetchingComments" class="loading-container">
|
||||||
|
<l-hatch size="28" stroke="4" speed="3.5" color="var(--primary-color)"></l-hatch>
|
||||||
|
</div>
|
||||||
|
<div v-else class="comments-container">
|
||||||
<BaseTimeline :items="comments">
|
<BaseTimeline :items="comments">
|
||||||
<template #item="{ item }">
|
<template #item="{ item }">
|
||||||
<CommentItem :key="item.id" :comment="item" :level="0" :default-show-replies="item.openReplies"
|
<CommentItem :key="item.id" :comment="item" :level="0" :default-show-replies="item.openReplies"
|
||||||
@deleted="onCommentDeleted" />
|
@deleted="onCommentDeleted" />
|
||||||
</template>
|
</template>
|
||||||
</BaseTimeline>
|
</BaseTimeline>
|
||||||
<!-- <CommentItem
|
|
||||||
v-for="comment in comments"
|
|
||||||
:key="comment.id"
|
|
||||||
:comment="comment"
|
|
||||||
:level="0"
|
|
||||||
:default-show-replies="comment.openReplies"
|
|
||||||
ref="postItems"
|
|
||||||
/> -->
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@@ -155,6 +150,7 @@ export default {
|
|||||||
const currentIndex = ref(1)
|
const currentIndex = ref(1)
|
||||||
const subscribed = ref(false)
|
const subscribed = ref(false)
|
||||||
const commentSort = ref('NEWEST')
|
const commentSort = ref('NEWEST')
|
||||||
|
const isFetchingComments = ref(false)
|
||||||
|
|
||||||
// record default metadata from the main document
|
// record default metadata from the main document
|
||||||
const defaultTitle = document.title
|
const defaultTitle = document.title
|
||||||
@@ -527,11 +523,13 @@ export default {
|
|||||||
return Promise.resolve([
|
return Promise.resolve([
|
||||||
{ id: 'NEWEST', name: '最新', icon: 'fas fa-clock' },
|
{ id: 'NEWEST', name: '最新', icon: 'fas fa-clock' },
|
||||||
{ id: 'OLDEST', name: '最旧', icon: 'fas fa-hourglass-start' },
|
{ id: 'OLDEST', name: '最旧', icon: 'fas fa-hourglass-start' },
|
||||||
{ id: 'MOST_INTERACTIONS', name: '最多互动', icon: 'fas fa-fire' }
|
// { id: 'MOST_INTERACTIONS', name: '最多互动', icon: 'fas fa-fire' }
|
||||||
])
|
])
|
||||||
}
|
}
|
||||||
|
|
||||||
const fetchComments = async () => {
|
const fetchComments = async () => {
|
||||||
|
isFetchingComments.value = true
|
||||||
|
await new Promise(resolve => setTimeout(resolve, 1000))
|
||||||
try {
|
try {
|
||||||
const token = getToken()
|
const token = getToken()
|
||||||
const res = await fetch(`${API_BASE_URL}/api/posts/${postId}/comments?sort=${commentSort.value}`, {
|
const res = await fetch(`${API_BASE_URL}/api/posts/${postId}/comments?sort=${commentSort.value}`, {
|
||||||
@@ -545,6 +543,8 @@ export default {
|
|||||||
}
|
}
|
||||||
} catch {
|
} catch {
|
||||||
// ignore
|
// ignore
|
||||||
|
} finally {
|
||||||
|
isFetchingComments.value = false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -622,7 +622,8 @@ export default {
|
|||||||
isMobile,
|
isMobile,
|
||||||
pinnedAt,
|
pinnedAt,
|
||||||
commentSort,
|
commentSort,
|
||||||
fetchCommentSorts
|
fetchCommentSorts,
|
||||||
|
isFetchingComments
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user