File tree Expand file tree Collapse file tree 2 files changed +15
-7
lines changed
apps/web/src/app/(profile)/profile/[handle]/(user)/(overview)/panels/Comments Expand file tree Collapse file tree 2 files changed +15
-7
lines changed Original file line number Diff line number Diff line change 1+ 'use client'
2+
13import type { Comments , UserType } from "@/types/users" ;
24import { postComment } from "@/utils/api" ;
35import { USER_DEFAULT_AVATAR } from "@/utils/constants" ;
46import { UserComment } from "@mav/ui/components/comments" ;
7+ import { useState } from "react" ;
58
69export default function CommentThread ( { comment, user } : { comment : Comments ; user : UserType } ) {
10+ const [ viewReplies , setViewReplies ] = useState ( false ) ;
11+ const toggleViewReplies = ( ) => setViewReplies ( ( prev ) => ! prev ) ;
712 return (
813 < div className = "space-y-4" >
914 < UserComment
1015 key = { comment . id }
1116 imgTag = { < img /> }
1217 date = { comment . createdAt }
18+ replies = { comment . replies . length }
19+ viewReplies = { viewReplies }
1320 onReply = { postComment }
21+ toggleViewReplies = { toggleViewReplies }
1422 commentId = { comment . id }
1523 avatar = { comment . author . avatarUrl || USER_DEFAULT_AVATAR }
1624 handle = { comment . author . handle }
@@ -21,7 +29,7 @@ export default function CommentThread({ comment, user }: { comment: Comments; us
2129
2230 { comment . replies . length > 0 && (
2331 < div className = "ml-8 pl-4 space-y-4" >
24- { comment . replies . map ( ( reply ) => (
32+ { viewReplies && comment . replies . map ( ( reply ) => (
2533 < CommentThread key = { reply . id } comment = { reply } user = { user } />
2634 ) ) }
2735 </ div >
Original file line number Diff line number Diff line change @@ -14,9 +14,10 @@ interface CommentProps extends React.ComponentProps<typeof CommentBase> {
1414 userRole ?: string
1515 isPinned ?: true
1616 upvotes ?: string
17- reply ?: CommentProps [ ]
1817 parentId ?: string
19- replies ?: CommentProps [ ]
18+ replies ?: number
19+ toggleViewReplies ?: ( ) => void
20+ viewReplies ?: boolean
2021 date ?: string
2122 onReply : (
2223 commentType : string ,
@@ -31,7 +32,6 @@ interface CommentProps extends React.ComponentProps<typeof CommentBase> {
3132
3233export function UserComment ( props : React . PropsWithChildren < CommentProps > ) {
3334 const [ showReplyInput , setShowReplyInput ] = useState ( false )
34- const [ replyText , setReplyText ] = useState ( "" )
3535 const toggleReplyInput = ( ) => setShowReplyInput ( ! showReplyInput )
3636
3737 const date = new Date ( props . date || "" )
@@ -49,9 +49,9 @@ export function UserComment(props: React.PropsWithChildren<CommentProps>) {
4949 < Button size = "small" className = "transition-none" variant = "tritery" onClick = { toggleReplyInput } >
5050 Reply
5151 </ Button >
52- { props . reply && props . reply ?. length > 0 && (
53- < Button size = "small" className = "transition-none" variant = "primary" >
54- View { props . reply ?. length } Replies
52+ { ( props . replies || 0 ) > 0 && props . toggleViewReplies && (
53+ < Button size = "small" className = "transition-none" variant = "primary" onClick = { props . toggleViewReplies } >
54+ View { props . replies } Replies
5555 </ Button >
5656 ) }
5757 < div className = "w-full" >
You can’t perform that action at this time.
0 commit comments