Skip to content

Commit ac70d0a

Browse files
committed
chore: view replies function
1 parent bee9798 commit ac70d0a

File tree

2 files changed

+15
-7
lines changed
  • apps/web/src/app/(profile)/profile/[handle]/(user)/(overview)/panels/Comments
  • packages/ui/components/comments

2 files changed

+15
-7
lines changed

apps/web/src/app/(profile)/profile/[handle]/(user)/(overview)/panels/Comments/Thread.tsx

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,24 @@
1+
'use client'
2+
13
import type { Comments, UserType } from "@/types/users";
24
import { postComment } from "@/utils/api";
35
import { USER_DEFAULT_AVATAR } from "@/utils/constants";
46
import { UserComment } from "@mav/ui/components/comments";
7+
import { useState } from "react";
58

69
export 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>

packages/ui/components/comments/UserComment.tsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff 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

3233
export 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">

0 commit comments

Comments
 (0)