Files
Dwinzo_Demo/app/src/modules/collaboration/comments/instances/commentInstances.tsx

58 lines
2.3 KiB
TypeScript
Raw Normal View History

import React, { useEffect } from "react";
import CommentInstance from "./commentInstance/commentInstance";
import { getAllThreads } from "../../../../services/factoryBuilder/comments/getAllThreads";
import { useParams } from "react-router-dom";
import { getUserData } from "../../../../functions/getUserData";
import { getRelativeTime } from "../../../../components/ui/collaboration/function/getRelativeTime";
import { useSceneContext } from "../../../scene/sceneContext";
2025-06-23 09:37:53 +05:30
2025-06-10 15:28:23 +05:30
function CommentInstances() {
2025-06-23 09:37:53 +05:30
const { projectId } = useParams();
const { userId } = getUserData();
2025-09-10 11:18:47 +05:30
const { versionStore, commentStore } = useSceneContext();
const { comments, setComments } = commentStore();
const { selectedVersion } = versionStore();
2025-09-02 15:21:13 +05:30
useEffect(() => {
// console.log("comments", comments);
}, [comments]);
2025-06-23 09:37:53 +05:30
2025-09-02 15:21:13 +05:30
useEffect(() => {
if (!projectId || !selectedVersion) return;
getAllThreads(projectId, selectedVersion?.versionId)
.then((fetchedComments) => {
const formattedThreads = Array.isArray(fetchedComments.data)
? fetchedComments.data.map((thread: any) => ({
...thread,
comments: Array.isArray(thread.comments)
? thread.comments.map((val: any) => ({
replyId: val._id ?? "",
creatorId: userId,
createdAt: getRelativeTime(val.createdAt),
lastUpdatedAt: "1 hr ago",
comment: val.comment,
_id: val._id ?? "",
}))
: [],
}))
: [];
setComments(formattedThreads);
})
.catch((err) => {
console.error("Failed to fetch threads:", err);
});
2025-09-10 11:18:47 +05:30
}, [projectId, selectedVersion]);
2025-06-10 15:28:23 +05:30
return (
<>
2025-06-23 09:37:53 +05:30
{comments?.map((comment: CommentSchema) => (
<React.Fragment key={comment.threadId}>
2025-06-10 15:28:23 +05:30
<CommentInstance comment={comment} />
</React.Fragment>
))}
</>
);
2025-06-10 15:28:23 +05:30
}
export default CommentInstances;