feat: dynamic loading of comments

This commit is contained in:
DIYgod
2023-06-15 23:45:35 +01:00
parent fc9e02e1ed
commit 34e32711b2
3 changed files with 14 additions and 4 deletions
+3 -1
View File
@@ -9,7 +9,7 @@ import { ExpandedNote } from "~/lib/types"
import { cn } from "~/lib/utils"
import { useGetComments } from "~/queries/page"
export const Comment = ({
const Comment = ({
page,
className,
}: {
@@ -90,3 +90,5 @@ const Loader = () => {
</div>
)
}
export default Comment
+9 -2
View File
@@ -1,13 +1,14 @@
"use client"
import { useInViewport } from "ahooks"
import dynamic from "next/dynamic"
import { useEffect, useRef } from "react"
import { useQuery, useQueryClient } from "@tanstack/react-query"
import { Comment } from "~/components/common/Comment"
import { ReactionLike } from "~/components/common/ReactionLike"
import { ReactionTip } from "~/components/common/ReactionTip"
import { useTranslation } from "~/lib/i18n/client"
import { ExpandedCharacter, ExpandedNote } from "~/lib/types"
const key = ["PostFooterInView"]
@@ -34,6 +35,12 @@ export const PostFooter = ({
queryClient.setQueryData(key, () => isInView)
}, [isInView])
const { t } = useTranslation("common")
const DynamicComment = dynamic(() => import("~/components/common/Comment"), {
loading: () => <p>{t("Loading comments")}...</p>,
})
return (
<>
<div
@@ -50,7 +57,7 @@ export const PostFooter = ({
page={page}
/>
</div>
<Comment page={page} />
<DynamicComment page={page} />
</>
)
}
+2 -1
View File
@@ -88,5 +88,6 @@
"Comment Without Login": "免登录评论",
"Name": "昵称",
"Email": "电子邮箱",
"You'll use an official public account for comments and give up blockchain ownership": "你将使用官方公共账号进行评论并放弃区块链所有权"
"You'll use an official public account for comments and give up blockchain ownership": "你将使用官方公共账号进行评论并放弃区块链所有权",
"Loading comments": "加载评论中"
}