Merge remote-tracking branch 'origin/dev-collaboration' into main-dev

This commit is contained in:
2025-06-24 11:57:37 +05:30
8 changed files with 99 additions and 57 deletions

View File

@@ -5,16 +5,19 @@ import { getAllThreads } from '../../../../services/factoryBuilder/comments/getA
import { useParams } from 'react-router-dom';
import { getUserData } from '../../../../functions/getUserData';
import { getRelativeTime } from '../../../../components/ui/collaboration/function/getRelativeTime';
import { useVersionContext } from '../../../builder/version/versionContext';
function CommentInstances() {
const { comments, setComments } = useCommentStore();
const { projectId } = useParams();
const { userId } = getUserData()
const { userId } = getUserData();
const { selectedVersionStore } = useVersionContext();
const { selectedVersion } = selectedVersionStore();
const getThreads = async () => {
if (!projectId) return;
if (!projectId || !selectedVersion) return;
try {
const getComments = await getAllThreads(projectId);
const getComments = await getAllThreads(projectId, selectedVersion?.versionId);
const formattedThreads = Array.isArray(getComments.data)
? getComments.data.map((thread: any) => ({

View File

@@ -14,12 +14,13 @@ interface ThreadSocketProps {
const ThreadSocketResponsesDev = ({ setMessages, modeRef, messages }: ThreadSocketProps) => {
const { threadSocket } = useSocketStore();
const { selectedComment, setSelectedComment, setCommentPositionState, commentPositionState } = useSelectedComment();
const { comments, addComment, addReply, updateComment, updateReply } = useCommentStore();
const { comments, removeReply, addComment, addReply, updateComment, updateReply } = useCommentStore();
const { userId } = getUserData();
useEffect(() => {
if (!threadSocket) return;
// --- Add Comment Handler ---
// const handleAddComment = (data: any) => {
//
@@ -55,52 +56,56 @@ const ThreadSocketResponsesDev = ({ setMessages, modeRef, messages }: ThreadSock
// };
// threadSocket.on('v1-Comment:response:add', handleAddComment);
const handleAddComment = (data: any) => {
// console.log('Add: ', data);
const commentData = {
replyId: data.data?._id,
creatorId: data.data?.userId,
createdAt: getRelativeTime(data.data?.createdAt),
lastUpdatedAt: "2 hrs ago",
comment: data.data.comment,
comment: data.data?.comment,
};
if (modeRef.current === "create") {
addReply(selectedComment?.threadId, commentData);
setMessages((prevMessages) => [...prevMessages, commentData]);
} else if (modeRef.current === "edit") {
updateReply(selectedComment?.threadId, data.data?._id, commentData);
setMessages((prev) =>
prev.map((message) => {
// 👈 log each message
return message.replyId === data.data?._id
? { ...message, comment: data.data?.comment }
: message;
})
);
// console.log('data.data?.comment: ', data.data?.comment);
} else {
}
threadSocket.off("v1-Comment:response:add", handleAddComment);
};
threadSocket.on('v1-Comment:response:add', handleAddComment);
// --- Delete Comment Handler ---
const handleDeleteComment = (data: any) => {
// console.log('delete: ', data);
threadSocket.off('v1-Comment:response:delete', handleDeleteComment);
// setMessages(prev => {
// // 👈 logs the current state
// return prev.filter(message => message.replyId !== data.data._id);
// });
// removeReply(selectedComment?.threadId, data.data._id);
//
};
threadSocket.on('v1-Comment:response:delete', handleDeleteComment);
// --- Create Thread Handler ---
const handleCreateThread = (data: any) => {
// console.log('createThread: ', data);
const comment: CommentSchema = {
state: 'active',
@@ -117,20 +122,28 @@ const ThreadSocketResponsesDev = ({ setMessages, modeRef, messages }: ThreadSock
addComment(comment);
setCommentPositionState(null);
// setSelectedComment(null);
threadSocket.off('v1-thread:response:create', handleCreateThread);
};
threadSocket.on('v1-thread:response:create', handleCreateThread);
// --- Delete Thread Handler ---
// const handleDeleteThread = (data: any) => {
//
// };
// threadSocket.on("v1-thread:response:delete", handleDeleteThread);
console.log(
"del"
);
const handleDeleteThread = (data: any) => {
threadSocket.off('v1-thread:response:delete', handleDeleteThread);
};
threadSocket.on('v1-thread:response:delete', handleDeleteThread);
threadSocket.on("v1-thread:response:delete", handleDeleteThread);
const handleEditThread = (data: any) => {
const editedThread: CommentSchema = {
state: 'active',
threadId: data.data?._id,
@@ -138,17 +151,16 @@ const ThreadSocketResponsesDev = ({ setMessages, modeRef, messages }: ThreadSock
createdAt: data.data?.createdAt,
threadTitle: data.data?.threadTitle,
lastUpdatedAt: new Date().toISOString(),
position: data.data.position,
position: data.data?.position,
rotation: [0, 0, 0],
comments: data.data.comments,
comments: data.data?.comments,
};
// console.log('data.data?._id: ', data.data?._id);
//
updateComment(data.data?._id, editedThread);
setSelectedComment(editedThread)
// setSelectedComment(null);
};
threadSocket.on('v1-thread:response:updateTitle', handleEditThread);