fix: comment list height in post modal

This commit is contained in:
DIYgod 2023-06-29 22:55:16 +01:00
parent a0ea3c20e8
commit c428dc50de
No known key found for this signature in database
1 changed files with 9 additions and 1 deletions

View File

@ -1,5 +1,6 @@
"use client"
import { useState } from "react"
// TODO
import { Virtuoso } from "react-virtuoso"
@ -29,6 +30,8 @@ const Comment = ({
(page) => (page?.list?.length ?? 0) > 0,
)
const [totalListHeight, setTotalListHeight] = useState(1)
return (
<div
className={cn("xlog-comment comment", className)}
@ -55,7 +58,7 @@ const Comment = ({
<Virtuoso
className="xlog-comment-list"
style={{
maxHeight: fixHeight ? "80vh" : undefined,
height: fixHeight ? totalListHeight : undefined,
}}
useWindowScroll={!fixHeight}
data={data}
@ -63,6 +66,11 @@ const Comment = ({
components={{
Footer: comments.isLoading ? Loader : undefined,
}}
totalListHeightChanged={(height) => {
if (fixHeight && height > 0) {
setTotalListHeight(Math.min(height + 71, 900))
}
}}
itemContent={(_, p) =>
p?.list?.map((comment, idx) => (
<CommentItem