code optimization

This commit is contained in:
2025-09-09 18:06:01 +05:30
parent dcc81e6224
commit f741e07994
5 changed files with 107 additions and 105 deletions

View File

@@ -11,6 +11,7 @@ import { useSimulationManager } from "../../../store/rough/useSimulationManagerS
import { useParams } from "react-router-dom"; import { useParams } from "react-router-dom";
import { validateSimulationDataApi } from "../../../services/simulation/comparison/validateSimulationDataApi"; import { validateSimulationDataApi } from "../../../services/simulation/comparison/validateSimulationDataApi";
import { calculateSimulationData } from "./functions/calculateSimulationData"; import { calculateSimulationData } from "./functions/calculateSimulationData";
type AssetData = { type AssetData = {
activeTime: number; activeTime: number;
idleTime: number; idleTime: number;

View File

@@ -73,7 +73,15 @@ const ThreadChat: React.FC = () => {
if (event.button !== 0) return; if (event.button !== 0) return;
// Avoid dragging if a button, icon, textarea etc. was clicked // Avoid dragging if a button, icon, textarea etc. was clicked
const target = event.target as HTMLElement; 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; return;
} }
@@ -305,7 +313,20 @@ const ThreadChat: React.FC = () => {
<div className="messages-wrapper" ref={messagesRef}> <div className="messages-wrapper" ref={messagesRef}>
{selectedComment && <Messages val={selectedComment} i={1} key={selectedComment.creatorId} isEditableThread={true} setEditedThread={setEditedThread} editedThread={editedThread} />} {selectedComment && <Messages val={selectedComment} i={1} key={selectedComment.creatorId} isEditableThread={true} setEditedThread={setEditedThread} editedThread={editedThread} />}
{messages && messages.map((val, i) => <Messages val={val as any} i={i} key={val.replyId} setMessages={setMessages} setIsEditable={setIsEditable} isEditable={isEditable} isEditableThread={false} setMode={setMode} mode={mode} />)} {messages &&
messages.map((val, i) => (
<Messages
val={val as any}
i={i}
key={val.replyId}
setMessages={setMessages}
setIsEditable={setIsEditable}
isEditable={isEditable}
isEditableThread={false}
setMode={setMode}
mode={mode}
/>
))}
</div> </div>
<div className="send-message-wrapper"> <div className="send-message-wrapper">

View File

@@ -28,7 +28,7 @@ function CommentsGroup() {
if (evt.button === 0) { if (evt.button === 0) {
isLeftMouseDown = false; isLeftMouseDown = false;
} }
} };
const onMouseMove = () => { const onMouseMove = () => {
if (isLeftMouseDown) { if (isLeftMouseDown) {
@@ -83,18 +83,17 @@ function CommentsGroup() {
if (intersects.length > 0) { if (intersects.length > 0) {
const position = new Vector3(intersects[0].point.x, Math.max(intersects[0].point.y, 0), intersects[0].point.z); const position = new Vector3(intersects[0].point.x, Math.max(intersects[0].point.y, 0), intersects[0].point.z);
setSelectedComment(null); setSelectedComment(null);
setCommentPositionState({ position: position.toArray() }) setCommentPositionState({ position: position.toArray() });
position.project(camera); position.project(camera);
const x = (position.x * 0.5 + 0.5) * size.width; const x = (position.x * 0.5 + 0.5) * size.width;
const y = (-(position.y * 0.5) + 0.5) * size.height; const y = (-(position.y * 0.5) + 0.5) * size.height;
setPosition2Dstate({ x, y }) setPosition2Dstate({ x, y });
setHoverPos(null); setHoverPos(null);
} }
} };
if (activeTool === 'comment') { if (activeTool === "comment") {
canvasElement.addEventListener("mousedown", onMouseDown); canvasElement.addEventListener("mousedown", onMouseDown);
canvasElement.addEventListener("mouseup", onMouseUp); canvasElement.addEventListener("mouseup", onMouseUp);
canvasElement.addEventListener("mousemove", onMouseMove); canvasElement.addEventListener("mousemove", onMouseMove);
@@ -109,18 +108,18 @@ function CommentsGroup() {
canvasElement.removeEventListener("mousemove", onMouseMove); canvasElement.removeEventListener("mousemove", onMouseMove);
canvasElement.removeEventListener("click", onMouseClick); canvasElement.removeEventListener("click", onMouseClick);
}; };
}, [activeTool, camera]) }, [activeTool, camera]);
return ( return (
<> <>
<CommentInstances /> <CommentInstances />
{hoverPos && ( {hoverPos && (
<Sphere name={'commentHolder'} args={[0.1, 16, 16]} position={hoverPos}> <Sphere name={"commentHolder"} args={[0.1, 16, 16]} position={hoverPos}>
<meshStandardMaterial color="orange" /> <meshStandardMaterial color="orange" />
</Sphere> </Sphere>
)} )}
</> </>
) );
} }
export default CommentsGroup export default CommentsGroup;

View File

@@ -112,11 +112,6 @@ export const useToolMode = create<any>((set: any) => ({
setToolMode: (x: any) => set(() => ({ toolMode: x })), setToolMode: (x: any) => set(() => ({ toolMode: x })),
})); }));
export const useSetScale = create<any>((set: any) => ({
scale: null,
setScale: (x: any) => set(() => ({ scale: x })),
}));
export const useRoofVisibility = create<any>((set: any) => ({ export const useRoofVisibility = create<any>((set: any) => ({
roofVisibility: false, roofVisibility: false,
setRoofVisibility: (x: any) => set(() => ({ roofVisibility: x })), setRoofVisibility: (x: any) => set(() => ({ roofVisibility: x })),
@@ -137,16 +132,6 @@ export const useSunPosition = create<any>((set: any) => ({
setSunPosition: (newSuntPosition: any) => set({ sunPosition: newSuntPosition }), setSunPosition: (newSuntPosition: any) => set({ sunPosition: newSuntPosition }),
})); }));
export const useRemoveLayer = create<any>((set: any) => ({
removeLayer: false,
setRemoveLayer: (x: any) => set(() => ({ removeLayer: x })),
}));
export const useRemovedLayer = create<any>((set: any) => ({
removedLayer: null,
setRemovedLayer: (x: any) => set(() => ({ removedLayer: x })),
}));
export const useProjectName = create<any>((set: any) => ({ export const useProjectName = create<any>((set: any) => ({
projectName: "Creating Your Project", projectName: "Creating Your Project",
setProjectName: (x: any) => set({ projectName: x }), setProjectName: (x: any) => set({ projectName: x }),

View File

@@ -2,96 +2,92 @@ import { create } from "zustand";
import { immer } from "zustand/middleware/immer"; import { immer } from "zustand/middleware/immer";
interface CommentStore { interface CommentStore {
comments: CommentsSchema; comments: CommentsSchema;
// Comment operations // Comment operations
addComment: (comment: CommentSchema) => void; addComment: (comment: CommentSchema) => void;
setComments: (comments: CommentsSchema) => void; setComments: (comments: CommentsSchema) => void;
updateComment: (threadId: string, updates: Partial<CommentSchema>) => void; updateComment: (threadId: string, updates: Partial<CommentSchema>) => void;
removeComment: (threadId: string) => void; removeComment: (threadId: string) => void;
// Reply operations // Reply operations
addReply: (threadId: string, reply: Reply) => void; addReply: (threadId: string, reply: Reply) => void;
updateReply: ( updateReply: (threadId: string, replyId: string, updates: Partial<Reply>) => void;
threadId: string, removeReply: (threadId: string, _id: string) => void;
replyId: string,
updates: Partial<Reply>
) => void;
removeReply: (threadId: string, _id: string) => void;
// Getters // Getters
getCommentById: (threadId: string) => CommentSchema | undefined; getCommentById: (threadId: string) => CommentSchema | undefined;
} }
export const useCommentStore = create<CommentStore>()( export const useCommentStore = create<CommentStore>()(
immer((set, get) => ({ immer((set, get) => ({
comments: [], comments: [],
// Comment operations // Comment operations
addComment: (comment) => { addComment: (comment) => {
set((state) => { set((state) => {
if (!state.comments.find((c) => c.threadId === comment.threadId)) { if (!state.comments.find((c) => c.threadId === comment.threadId)) {
state.comments.push(JSON.parse(JSON.stringify(comment))); state.comments.push(JSON.parse(JSON.stringify(comment)));
} }
}); });
}, },
setComments: (comments) => { setComments: (comments) => {
set((state) => { set((state) => {
state.comments = comments; state.comments = comments;
}); });
}, },
updateComment: (threadId, updates) => { updateComment: (threadId, updates) => {
console.log("threadId:updater ", threadId); console.log("threadId:updater ", threadId);
set((state) => { set((state) => {
const comment = state.comments.find((c) => c.threadId === threadId); const comment = state.comments.find((c) => c.threadId === threadId);
if (comment) { if (comment) {
Object.assign(comment, updates); Object.assign(comment, updates);
} }
}); });
}, },
removeComment: (threadId) => { removeComment: (threadId) => {
set((state) => { set((state) => {
state.comments = state.comments.filter((c) => c.threadId !== threadId); state.comments = state.comments.filter((c) => c.threadId !== threadId);
}); });
}, },
// Reply operations // Reply operations
addReply: (threadId, comment) => { addReply: (threadId, comment) => {
set((state) => { set((state) => {
const reply = state.comments.find((c) => c.threadId === threadId); const reply = state.comments.find((c) => c.threadId === threadId);
if (reply) { if (reply) {
reply.comments.push(comment); reply.comments.push(comment);
} }
}); });
}, },
updateReply: (threadId, replyId, updates) => { updateReply: (threadId, replyId, updates) => {
set((state) => { set((state) => {
const reply = state.comments.find((c) => c.threadId === threadId); const reply = state.comments.find((c) => c.threadId === threadId);
if (reply) { if (reply) {
const comment = reply.comments.find((r) => r.replyId === replyId); const comment = reply.comments.find((r) => r.replyId === replyId);
if (comment) { if (comment) {
Object.assign(comment, updates); Object.assign(comment, updates);
} }
} }
}); });
}, },
removeReply: (threadId, _id) => { removeReply: (threadId, _id) => {
set((state) => { set((state) => {
const comment = state.comments.find((c) => c.threadId === threadId); const comment = state.comments.find((c) => c.threadId === threadId);
if (comment) { if (comment) {
comment.comments = comment.comments.filter((r) => r.replyId !== _id); comment.comments = comment.comments.filter((r) => r.replyId !== _id);
} }
}); });
}, },
// Getter // Getter
getCommentById: (threadId) => { getCommentById: (threadId) => {
return get().comments.find((c) => c.threadId === threadId); return get().comments.find((c) => c.threadId === threadId);
}, },
})) }))
); );