Files
Dwinzo_Demo/app/src/modules/collaboration/threads/threadInstances/threadInstances.tsx

58 lines
2.3 KiB
TypeScript
Raw Normal View History

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";
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();
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();
const { selectedVersion } = versionStore();
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;
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);
})
.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-06-10 15:28:23 +05:30
}
2025-09-10 11:44:15 +05:30
export default ThreadInstances;