82 lines
2.1 KiB
TypeScript
82 lines
2.1 KiB
TypeScript
import { useTranslation } from "next-i18next"
|
|
import { Virtuoso } from "react-virtuoso"
|
|
|
|
import { CommentInput } from "~/components/common/CommentInput"
|
|
import { CommentItem } from "~/components/common/CommentItem"
|
|
import { Note } from "~/lib/types"
|
|
import { cn } from "~/lib/utils"
|
|
import { useGetComments } from "~/queries/page"
|
|
|
|
export const Comment: React.FC<{
|
|
page?: Note | null
|
|
className?: string
|
|
}> = ({ page, className }) => {
|
|
const comments = useGetComments({
|
|
pageId: page?.id,
|
|
})
|
|
const { t } = useTranslation("common")
|
|
|
|
return (
|
|
<div
|
|
className={cn("xlog-comment comment", className)}
|
|
id="comments"
|
|
data-hide-print
|
|
>
|
|
<div className="xlog-comment-count border-b pb-2 mb-6">
|
|
<span>
|
|
{comments.isLoading
|
|
? t("Loading")
|
|
: comments.data?.pages?.[0]?.count || "0"}{" "}
|
|
{t(
|
|
`Comment${
|
|
comments.data?.pages?.[0]?.count &&
|
|
comments.data.pages[0].count > 1
|
|
? "s"
|
|
: ""
|
|
}`,
|
|
)}
|
|
</span>
|
|
</div>
|
|
<CommentInput pageId={page?.id} />
|
|
|
|
<Virtuoso
|
|
className="xlog-comment-list"
|
|
useWindowScroll
|
|
data={comments.data?.pages}
|
|
endReached={() => comments.fetchNextPage()}
|
|
components={{
|
|
Footer: comments.isLoading ? Loader : undefined,
|
|
}}
|
|
itemContent={(_, p) =>
|
|
p?.list?.map((comment, idx) => (
|
|
<CommentItem
|
|
className="mt-6"
|
|
originalId={page?.id}
|
|
comment={comment}
|
|
key={comment.transactionHash}
|
|
depth={0}
|
|
/>
|
|
))
|
|
}
|
|
></Virtuoso>
|
|
{comments.isLoading && (
|
|
<div className="relative mt-4 w-full text-sm text-center py-4">
|
|
{t("Loading")}...
|
|
</div>
|
|
)}
|
|
</div>
|
|
)
|
|
}
|
|
|
|
const Loader = () => {
|
|
const { t } = useTranslation("common")
|
|
return (
|
|
<div
|
|
className="relative mt-4 w-full text-sm text-center py-4"
|
|
key={"loading"}
|
|
>
|
|
{t("Loading")}...
|
|
</div>
|
|
)
|
|
}
|