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 { validateSimulationDataApi } from "../../../services/simulation/comparison/validateSimulationDataApi";
import { calculateSimulationData } from "./functions/calculateSimulationData";
type AssetData = {
activeTime: number;
idleTime: number;

View File

@@ -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 = () => {
<div className="messages-wrapper" ref={messagesRef}>
{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 className="send-message-wrapper">

View File

@@ -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 (
<>
<CommentInstances />
{hoverPos && (
<Sphere name={'commentHolder'} args={[0.1, 16, 16]} position={hoverPos}>
<Sphere name={"commentHolder"} args={[0.1, 16, 16]} position={hoverPos}>
<meshStandardMaterial color="orange" />
</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 })),
}));
export const useSetScale = create<any>((set: any) => ({
scale: null,
setScale: (x: any) => set(() => ({ scale: x })),
}));
export const useRoofVisibility = create<any>((set: any) => ({
roofVisibility: false,
setRoofVisibility: (x: any) => set(() => ({ roofVisibility: x })),
@@ -137,16 +132,6 @@ export const useSunPosition = create<any>((set: any) => ({
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) => ({
projectName: "Creating Your Project",
setProjectName: (x: any) => set({ projectName: x }),

View File

@@ -12,11 +12,7 @@ interface CommentStore {
// Reply operations
addReply: (threadId: string, reply: Reply) => void;
updateReply: (
threadId: string,
replyId: string,
updates: Partial<Reply>
) => void;
updateReply: (threadId: string, replyId: string, updates: Partial<Reply>) => void;
removeReply: (threadId: string, _id: string) => void;
// Getters