mirror of
https://github.com/snowykami/neo-blog.git
synced 2025-09-26 11:06:23 +00:00
Fix comment pagination bug - prevent comments from disappearing on load more
Co-authored-by: snowykami <79104275+snowykami@users.noreply.github.com>
This commit is contained in:
@ -34,19 +34,27 @@ export function CommentSection(
|
|||||||
const [needLoadMore, setNeedLoadMore] = useState(true); // 是否需要加载更多,当最后一次获取的评论数小于分页大小时设为false
|
const [needLoadMore, setNeedLoadMore] = useState(true); // 是否需要加载更多,当最后一次获取的评论数小于分页大小时设为false
|
||||||
// 加载0/顶层评论
|
// 加载0/顶层评论
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
// Reset pagination state when target changes
|
||||||
|
setPage(1);
|
||||||
|
setNeedLoadMore(true);
|
||||||
|
|
||||||
listComments({
|
listComments({
|
||||||
targetType,
|
targetType,
|
||||||
targetId,
|
targetId,
|
||||||
depth: 0,
|
depth: 0,
|
||||||
orderBy: OrderBy.CreatedAt,
|
orderBy: OrderBy.CreatedAt,
|
||||||
desc: true,
|
desc: true,
|
||||||
page: page,
|
page: 1,
|
||||||
size: config.commentsPerPage,
|
size: config.commentsPerPage,
|
||||||
commentId: 0
|
commentId: 0
|
||||||
}).then(response => {
|
}).then(response => {
|
||||||
setComments(response.data.comments);
|
setComments(response.data.comments);
|
||||||
|
// If we got fewer comments than requested, no more pages
|
||||||
|
if (response.data.comments.length < config.commentsPerPage) {
|
||||||
|
setNeedLoadMore(false);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}, [page, targetId, targetType]);
|
}, [targetId, targetType]);
|
||||||
|
|
||||||
const onCommentSubmitted = ({ commentContent, isPrivate, showClientInfo }: { commentContent: string, isPrivate: boolean, showClientInfo: boolean }) => {
|
const onCommentSubmitted = ({ commentContent, isPrivate, showClientInfo }: { commentContent: string, isPrivate: boolean, showClientInfo: boolean }) => {
|
||||||
createComment({
|
createComment({
|
||||||
|
Reference in New Issue
Block a user