From f741e07994f0ce1dc9d92e2a590f24babb99e664 Mon Sep 17 00:00:00 2001 From: Jerald-Golden-B Date: Tue, 9 Sep 2025 18:06:01 +0530 Subject: [PATCH] code optimization --- .../layout/scenes/ComparisonScene.tsx | 1 + .../ui/collaboration/ThreadChat.tsx | 25 ++- .../collaboration/comments/commentsGroup.tsx | 19 ++- app/src/store/builder/store.ts | 15 -- .../store/collaboration/useCommentStore.ts | 152 +++++++++--------- 5 files changed, 107 insertions(+), 105 deletions(-) diff --git a/app/src/components/layout/scenes/ComparisonScene.tsx b/app/src/components/layout/scenes/ComparisonScene.tsx index fd35601..3756b08 100644 --- a/app/src/components/layout/scenes/ComparisonScene.tsx +++ b/app/src/components/layout/scenes/ComparisonScene.tsx @@ -11,6 +11,7 @@ import { useSimulationManager } from "../../../store/rough/useSimulationManagerS import { useParams } from "react-router-dom"; import { validateSimulationDataApi } from "../../../services/simulation/comparison/validateSimulationDataApi"; import { calculateSimulationData } from "./functions/calculateSimulationData"; + type AssetData = { activeTime: number; idleTime: number; diff --git a/app/src/components/ui/collaboration/ThreadChat.tsx b/app/src/components/ui/collaboration/ThreadChat.tsx index ddbbf46..0bd4949 100644 --- a/app/src/components/ui/collaboration/ThreadChat.tsx +++ b/app/src/components/ui/collaboration/ThreadChat.tsx @@ -73,7 +73,15 @@ const ThreadChat: React.FC = () => { if (event.button !== 0) return; // Avoid dragging if a button, icon, textarea etc. was clicked const target = event.target as HTMLElement; - if (target.closest("button") || target.closest(".sent-button") || target.closest("textarea") || target.closest(".options-button") || target.closest(".options-list") || target.closest(".send-message-wrapper") || target.closest(".options delete")) { + if ( + target.closest("button") || + target.closest(".sent-button") || + target.closest("textarea") || + target.closest(".options-button") || + target.closest(".options-list") || + target.closest(".send-message-wrapper") || + target.closest(".options delete") + ) { return; } @@ -305,7 +313,20 @@ const ThreadChat: React.FC = () => {
{selectedComment && } - {messages && messages.map((val, i) => )} + {messages && + messages.map((val, i) => ( + + ))}
diff --git a/app/src/modules/collaboration/comments/commentsGroup.tsx b/app/src/modules/collaboration/comments/commentsGroup.tsx index c15e468..71eeb70 100644 --- a/app/src/modules/collaboration/comments/commentsGroup.tsx +++ b/app/src/modules/collaboration/comments/commentsGroup.tsx @@ -28,7 +28,7 @@ function CommentsGroup() { if (evt.button === 0) { isLeftMouseDown = false; } - } + }; const onMouseMove = () => { if (isLeftMouseDown) { @@ -83,18 +83,17 @@ function CommentsGroup() { if (intersects.length > 0) { const position = new Vector3(intersects[0].point.x, Math.max(intersects[0].point.y, 0), intersects[0].point.z); setSelectedComment(null); - setCommentPositionState({ position: position.toArray() }) - + setCommentPositionState({ position: position.toArray() }); position.project(camera); const x = (position.x * 0.5 + 0.5) * size.width; const y = (-(position.y * 0.5) + 0.5) * size.height; - setPosition2Dstate({ x, y }) + setPosition2Dstate({ x, y }); setHoverPos(null); } - } + }; - if (activeTool === 'comment') { + if (activeTool === "comment") { canvasElement.addEventListener("mousedown", onMouseDown); canvasElement.addEventListener("mouseup", onMouseUp); canvasElement.addEventListener("mousemove", onMouseMove); @@ -109,18 +108,18 @@ function CommentsGroup() { canvasElement.removeEventListener("mousemove", onMouseMove); canvasElement.removeEventListener("click", onMouseClick); }; - }, [activeTool, camera]) + }, [activeTool, camera]); return ( <> {hoverPos && ( - + )} - ) + ); } -export default CommentsGroup \ No newline at end of file +export default CommentsGroup; diff --git a/app/src/store/builder/store.ts b/app/src/store/builder/store.ts index 973f772..d4d295c 100644 --- a/app/src/store/builder/store.ts +++ b/app/src/store/builder/store.ts @@ -112,11 +112,6 @@ export const useToolMode = create((set: any) => ({ setToolMode: (x: any) => set(() => ({ toolMode: x })), })); -export const useSetScale = create((set: any) => ({ - scale: null, - setScale: (x: any) => set(() => ({ scale: x })), -})); - export const useRoofVisibility = create((set: any) => ({ roofVisibility: false, setRoofVisibility: (x: any) => set(() => ({ roofVisibility: x })), @@ -137,16 +132,6 @@ export const useSunPosition = create((set: any) => ({ setSunPosition: (newSuntPosition: any) => set({ sunPosition: newSuntPosition }), })); -export const useRemoveLayer = create((set: any) => ({ - removeLayer: false, - setRemoveLayer: (x: any) => set(() => ({ removeLayer: x })), -})); - -export const useRemovedLayer = create((set: any) => ({ - removedLayer: null, - setRemovedLayer: (x: any) => set(() => ({ removedLayer: x })), -})); - export const useProjectName = create((set: any) => ({ projectName: "Creating Your Project", setProjectName: (x: any) => set({ projectName: x }), diff --git a/app/src/store/collaboration/useCommentStore.ts b/app/src/store/collaboration/useCommentStore.ts index 92f6073..3fd5539 100644 --- a/app/src/store/collaboration/useCommentStore.ts +++ b/app/src/store/collaboration/useCommentStore.ts @@ -2,96 +2,92 @@ import { create } from "zustand"; import { immer } from "zustand/middleware/immer"; interface CommentStore { - comments: CommentsSchema; + comments: CommentsSchema; - // Comment operations - addComment: (comment: CommentSchema) => void; - setComments: (comments: CommentsSchema) => void; - updateComment: (threadId: string, updates: Partial) => void; - removeComment: (threadId: string) => void; + // Comment operations + addComment: (comment: CommentSchema) => void; + setComments: (comments: CommentsSchema) => void; + updateComment: (threadId: string, updates: Partial) => void; + removeComment: (threadId: string) => void; - // Reply operations - addReply: (threadId: string, reply: Reply) => void; - updateReply: ( - threadId: string, - replyId: string, - updates: Partial - ) => void; - removeReply: (threadId: string, _id: string) => void; + // Reply operations + addReply: (threadId: string, reply: Reply) => void; + updateReply: (threadId: string, replyId: string, updates: Partial) => void; + removeReply: (threadId: string, _id: string) => void; - // Getters - getCommentById: (threadId: string) => CommentSchema | undefined; + // Getters + getCommentById: (threadId: string) => CommentSchema | undefined; } export const useCommentStore = create()( - immer((set, get) => ({ - comments: [], + immer((set, get) => ({ + comments: [], - // Comment operations - addComment: (comment) => { - set((state) => { - if (!state.comments.find((c) => c.threadId === comment.threadId)) { - state.comments.push(JSON.parse(JSON.stringify(comment))); - } - }); - }, + // Comment operations + addComment: (comment) => { + set((state) => { + if (!state.comments.find((c) => c.threadId === comment.threadId)) { + state.comments.push(JSON.parse(JSON.stringify(comment))); + } + }); + }, - setComments: (comments) => { - set((state) => { - state.comments = comments; - }); - }, + setComments: (comments) => { + set((state) => { + state.comments = comments; + }); + }, - updateComment: (threadId, updates) => { - console.log("threadId:updater ", threadId); - set((state) => { - const comment = state.comments.find((c) => c.threadId === threadId); - if (comment) { - Object.assign(comment, updates); - } - }); - }, + updateComment: (threadId, updates) => { + console.log("threadId:updater ", threadId); + set((state) => { + const comment = state.comments.find((c) => c.threadId === threadId); + if (comment) { + Object.assign(comment, updates); + } + }); + }, - removeComment: (threadId) => { - set((state) => { - state.comments = state.comments.filter((c) => c.threadId !== threadId); - }); - }, + removeComment: (threadId) => { + set((state) => { + state.comments = state.comments.filter((c) => c.threadId !== threadId); + }); + }, - // Reply operations - addReply: (threadId, comment) => { - set((state) => { - const reply = state.comments.find((c) => c.threadId === threadId); - if (reply) { - reply.comments.push(comment); - } - }); - }, + // Reply operations + addReply: (threadId, comment) => { + set((state) => { + const reply = state.comments.find((c) => c.threadId === threadId); + if (reply) { + reply.comments.push(comment); + } + }); + }, - updateReply: (threadId, replyId, updates) => { - set((state) => { - const reply = state.comments.find((c) => c.threadId === threadId); - if (reply) { - const comment = reply.comments.find((r) => r.replyId === replyId); - if (comment) { - Object.assign(comment, updates); - } - } - }); - }, + updateReply: (threadId, replyId, updates) => { + set((state) => { + const reply = state.comments.find((c) => c.threadId === threadId); + if (reply) { + const comment = reply.comments.find((r) => r.replyId === replyId); + if (comment) { + Object.assign(comment, updates); + } + } + }); + }, - removeReply: (threadId, _id) => { - set((state) => { - const comment = state.comments.find((c) => c.threadId === threadId); - if (comment) { - comment.comments = comment.comments.filter((r) => r.replyId !== _id); - } - }); - }, + removeReply: (threadId, _id) => { + set((state) => { + const comment = state.comments.find((c) => c.threadId === threadId); + if (comment) { + comment.comments = comment.comments.filter((r) => r.replyId !== _id); + } + }); + }, - // Getter - getCommentById: (threadId) => { - return get().comments.find((c) => c.threadId === threadId); - }, - })) + // Getter + getCommentById: (threadId) => { + return get().comments.find((c) => c.threadId === threadId); + }, + })) );