2025-09-05 15:17:43 +05:30
|
|
|
import React, { useEffect } from "react";
|
2025-09-10 11:44:15 +05:30
|
|
|
import ThreadInstance from "./threadInstance/threadInstance";
|
|
|
|
|
import { getAllThreads } from "../../../../services/factoryBuilder/collab/comments/getAllThreads";
|
2025-09-05 15:17:43 +05:30
|
|
|
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-09-10 11:44:15 +05:30
|
|
|
function ThreadInstances() {
|
2025-06-23 09:37:53 +05:30
|
|
|
const { projectId } = useParams();
|
2025-06-24 11:56:26 +05:30
|
|
|
const { userId } = getUserData();
|
2025-09-10 11:44:15 +05:30
|
|
|
const { versionStore, threadStore } = useSceneContext();
|
2025-09-16 16:44:01 +05:30
|
|
|
const { threads, setThreads } = threadStore();
|
2025-09-05 15:17:43 +05:30
|
|
|
const { selectedVersion } = versionStore();
|
2025-06-23 10:54:17 +05:30
|
|
|
|
2025-09-02 15:21:13 +05:30
|
|
|
useEffect(() => {
|
2025-09-10 11:44:15 +05:30
|
|
|
// console.log("threads", threads);
|
|
|
|
|
}, [threads]);
|
2025-06-23 09:37:53 +05:30
|
|
|
|
2025-09-02 15:21:13 +05:30
|
|
|
useEffect(() => {
|
|
|
|
|
if (!projectId || !selectedVersion) return;
|
2025-09-05 15:17:43 +05:30
|
|
|
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 ?? "",
|
|
|
|
|
}))
|
|
|
|
|
: [],
|
|
|
|
|
}))
|
|
|
|
|
: [];
|
2025-09-16 16:44:01 +05:30
|
|
|
setThreads(formattedThreads);
|
2025-09-05 15:17:43 +05:30
|
|
|
})
|
|
|
|
|
.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-09-10 11:44:15 +05:30
|
|
|
{threads?.map((thread: ThreadSchema) => (
|
|
|
|
|
<React.Fragment key={thread.threadId}>
|
|
|
|
|
<ThreadInstance thread={thread} />
|
2025-06-10 15:28:23 +05:30
|
|
|
</React.Fragment>
|
|
|
|
|
))}
|
|
|
|
|
</>
|
2025-09-05 15:17:43 +05:30
|
|
|
);
|
2025-06-10 15:28:23 +05:30
|
|
|
}
|
|
|
|
|
|
2025-09-10 11:44:15 +05:30
|
|
|
export default ThreadInstances;
|