feat: enhance CommentThreads component with commentClicked prop and update reply structure

This commit is contained in:
Jerald-Golden-B 2025-05-22 17:02:48 +05:30
parent e8524cffd6
commit 07b98b92ee
4 changed files with 34 additions and 11 deletions

View File

@ -1,7 +1,11 @@
import React, { useState } from "react"; import React, { useState } from "react";
import { getAvatarColor } from "../../../modules/collaboration/functions/getAvatarColor"; import { getAvatarColor } from "../../../modules/collaboration/functions/getAvatarColor";
const CommentThreads: React.FC = () => { interface CommentThreadsProps {
commentClicked: () => void;
}
const CommentThreads: React.FC<CommentThreadsProps> = ({ commentClicked }) => {
const [expand, setExpand] = useState(false); const [expand, setExpand] = useState(false);
const commentsedUsers = [{ creatorId: "1" }]; const commentsedUsers = [{ creatorId: "1" }];
@ -12,11 +16,25 @@ const CommentThreads: React.FC = () => {
createdAt: "2 hours ago", createdAt: "2 hours ago",
comment: "Thread check", comment: "Thread check",
lastUpdatedAt: "string", lastUpdatedAt: "string",
replies: [], replies: [
{
replyId: 'string',
creatorId: 'string',
createdAt: 'string',
lastUpdatedAt: 'string',
reply: 'string',
},
{
replyId: 'string',
creatorId: 'string',
createdAt: 'string',
lastUpdatedAt: 'string',
reply: 'string',
}
],
}; };
function getUsername(userId: string) { function getUsername(userId: string) {
console.log(userId);
const UserName = "username"; const UserName = "username";
return UserName; return UserName;
} }
@ -24,6 +42,7 @@ const CommentThreads: React.FC = () => {
function getDetails(type?: "clicked") { function getDetails(type?: "clicked") {
if (type === "clicked") { if (type === "clicked") {
setExpand(true); setExpand(true);
commentClicked();
} else { } else {
setExpand((prev) => !prev); setExpand((prev) => !prev);
} }
@ -35,9 +54,8 @@ const CommentThreads: React.FC = () => {
onPointerEnter={() => getDetails()} onPointerEnter={() => getDetails()}
onPointerLeave={() => getDetails()} onPointerLeave={() => getDetails()}
onClick={() => getDetails("clicked")} onClick={() => getDetails("clicked")}
className={`comments-threads-container ${ className={`comments-threads-container ${expand ? "open" : "closed"
expand ? "open" : "closed" } unread`}
} unread`}
> >
<div className="users-commented"> <div className="users-commented">
{commentsedUsers.map((val, i) => ( {commentsedUsers.map((val, i) => (
@ -61,7 +79,7 @@ const CommentThreads: React.FC = () => {
</div> </div>
<div className="message">{CommentDetails.comment}</div> <div className="message">{CommentDetails.comment}</div>
{CommentDetails.replies.length > 0 && ( {CommentDetails.replies.length > 0 && (
<div className="replies">{CommentDetails.replies.length}</div> <div className="replies">{CommentDetails.replies.length} reply(s)</div>
)} )}
</div> </div>
</button> </button>

View File

@ -26,6 +26,11 @@ function CommentInstance({ comment }: { comment: CommentSchema }) {
return () => window.removeEventListener("keydown", handleKeyDown); return () => window.removeEventListener("keydown", handleKeyDown);
}, [selectedComment]); }, [selectedComment]);
const commentClicked = () => {
console.log('hii');
setSelectedComment(comment);
}
if (comment.state === 'inactive' || isPlaying) return null; if (comment.state === 'inactive' || isPlaying) return null;
return ( return (
@ -36,12 +41,12 @@ function CommentInstance({ comment }: { comment: CommentSchema }) {
zIndexRange={[1, 0]} zIndexRange={[1, 0]}
prepend prepend
sprite sprite
center center
position={comment.position} position={comment.position}
rotation={comment.rotation} rotation={comment.rotation}
className='comments-main-wrapper' className='comments-main-wrapper'
> >
<CommentThreads /> <CommentThreads commentClicked={commentClicked} />
</Html> </Html>
{CommentRef.current && transformMode && ( {CommentRef.current && transformMode && (
<TransformControls <TransformControls

View File

@ -6,7 +6,7 @@ function CommentInstances() {
const { comments } = useCommentStore(); const { comments } = useCommentStore();
useEffect(() => { useEffect(() => {
console.log('comments: ', comments); // console.log('comments: ', comments);
}, [comments]) }, [comments])
return ( return (

View File

@ -10,7 +10,7 @@ interface CommentSchema {
replies: Reply[]; replies: Reply[];
} }
export interface Reply { interface Reply {
replyId: string; replyId: string;
creatorId: string; creatorId: string;
createdAt: string; createdAt: string;