From 9e910f8d40ab95a12dfc5bb307710354a306c624 Mon Sep 17 00:00:00 2001 From: hookor Date: Fri, 31 May 2024 16:48:48 +0900 Subject: [PATCH] Fix: lazy load postDetail --- src/components/post/Comment.tsx | 4 ++-- src/components/post/PostComments.tsx | 33 +++++++++++++--------------- src/types/types.ts | 8 +++---- 3 files changed, 21 insertions(+), 24 deletions(-) diff --git a/src/components/post/Comment.tsx b/src/components/post/Comment.tsx index 33258e8f..fd82ab3a 100644 --- a/src/components/post/Comment.tsx +++ b/src/components/post/Comment.tsx @@ -2,7 +2,7 @@ import { useToggle } from '@/hooks/post/useToggle'; import CommentProto from '@/components/post/CommentProto'; import CheckReply from '@/components/post/CheckReply'; import Replies from '@/components/post/Replies'; -import { Comment } from '@/types/types'; +import { CommentType } from '@/types/types'; const Comment = ({ profileUrl, @@ -12,7 +12,7 @@ const Comment = ({ reply_count, postNum, id -}: Comment) => { +}: CommentType) => { const { toggle, handleToggle } = useToggle(); return ( <> diff --git a/src/components/post/PostComments.tsx b/src/components/post/PostComments.tsx index cdf6de06..8ec3afce 100644 --- a/src/components/post/PostComments.tsx +++ b/src/components/post/PostComments.tsx @@ -2,12 +2,13 @@ import React from 'react'; import { useId } from 'react'; import { useQuery } from '@tanstack/react-query'; import { getComments } from '@/api/post'; -import Comment from '@/components/post/Comment'; import { styled } from 'styled-system/jsx'; import { COMMENT_TEXTS, POST_TEXTS } from '@/constants/texts'; import { PaddingTB60 } from '@/styles/styles'; +import { CommentType } from '@/types/types'; const CTA = React.lazy(() => import('../common/CTA')); +const Comment = React.lazy(() => import('./Comment')); const { count } = COMMENT_TEXTS; const PostComments = ({ @@ -26,22 +27,6 @@ const PostComments = ({ }); const id = useId(); - const mapComment = (comment: Comment, idx: number) => { - return ( - - - - ); - }; - return ( <> {commentData && commentData.data.length !== 0 && ( @@ -50,7 +35,19 @@ const PostComments = ({ {commentCount} {count} - {commentData.data.map(mapComment)} + {commentData.data.map((comment: CommentType, idx: number) => { + + + ; + })} )} {commentData && commentData.data.length === 0 && ( diff --git a/src/types/types.ts b/src/types/types.ts index bb97ead7..00dc2485 100644 --- a/src/types/types.ts +++ b/src/types/types.ts @@ -1,4 +1,3 @@ -import InitialForm from '@/components/start/InitialForm'; import { Dayjs } from 'dayjs'; import { TouchEventHandler, @@ -172,7 +171,7 @@ export interface EditProfileImgProps profileImg?: string; } -export interface Comment { +export interface CommentType { profileUrl: string; nickname: string; content: string; @@ -182,13 +181,14 @@ export interface Comment { id: number; } -export interface CommentPrototype extends Omit { +export interface CommentPrototype + extends Omit { comment?: boolean; postNum?: string; parentCommentId?: number; } export type Reply = Pick< - Comment, + CommentType, 'profileUrl' | 'nickname' | 'content' | 'created_at' | 'id' >;