fix: comments not render when get empty list (#539)

This commit is contained in:
Birdgg
2023-05-15 16:06:03 +01:00
committed by GitHub
parent 09441cffce
commit 2df77a8cca
@@ -1,6 +1,7 @@
"use client"
import { useParams } from "next/navigation"
import { useEffect } from "react"
import { Virtuoso } from "react-virtuoso"
import { CommentItem } from "~/components/common/CommentItem"
@@ -21,6 +22,19 @@ export default function CommentsPage() {
characterId: site.data?.characterId,
})
// fetch next page when we get a empty list
useEffect(() => {
if (
comments.data?.pages &&
comments.data.pages.at(-1)?.list.length === 0 &&
comments.hasNextPage
) {
comments.fetchNextPage()
}
}, [comments.data, comments.hasNextPage, comments.fetchNextPage])
const data = comments.data?.pages.filter((page) => page.list.length > 0)
const feedUrl =
getSiteLink({
subdomain: subdomain,
@@ -47,7 +61,7 @@ export default function CommentsPage() {
<Virtuoso
className="xlog-comment-list"
useWindowScroll
data={comments.data?.pages}
data={data}
endReached={() =>
comments.hasNextPage && comments.fetchNextPage()
}