From 34e32711b2451a9a2767cf0c3cf731c4043b4f4e Mon Sep 17 00:00:00 2001 From: DIYgod Date: Thu, 15 Jun 2023 23:45:35 +0100 Subject: [PATCH] feat: dynamic loading of comments --- src/components/common/Comment.tsx | 4 +++- src/components/site/PostFooter.tsx | 11 +++++++++-- src/lib/i18n/locales/zh/common.json | 3 ++- 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/src/components/common/Comment.tsx b/src/components/common/Comment.tsx index bcf525be..94601a48 100644 --- a/src/components/common/Comment.tsx +++ b/src/components/common/Comment.tsx @@ -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 = () => { ) } + +export default Comment diff --git a/src/components/site/PostFooter.tsx b/src/components/site/PostFooter.tsx index c8658d88..07cbc522 100644 --- a/src/components/site/PostFooter.tsx +++ b/src/components/site/PostFooter.tsx @@ -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: () =>
{t("Loading comments")}...
, + }) + return ( <> -