code optimization
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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">
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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 }),
|
||||
|
||||
@@ -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<CommentSchema>) => void;
|
||||
removeComment: (threadId: string) => void;
|
||||
// Comment operations
|
||||
addComment: (comment: CommentSchema) => void;
|
||||
setComments: (comments: CommentsSchema) => void;
|
||||
updateComment: (threadId: string, updates: Partial<CommentSchema>) => void;
|
||||
removeComment: (threadId: string) => void;
|
||||
|
||||
// Reply operations
|
||||
addReply: (threadId: string, reply: Reply) => void;
|
||||
updateReply: (
|
||||
threadId: string,
|
||||
replyId: string,
|
||||
updates: Partial<Reply>
|
||||
) => void;
|
||||
removeReply: (threadId: string, _id: string) => void;
|
||||
// Reply operations
|
||||
addReply: (threadId: string, reply: Reply) => void;
|
||||
updateReply: (threadId: string, replyId: string, updates: Partial<Reply>) => void;
|
||||
removeReply: (threadId: string, _id: string) => void;
|
||||
|
||||
// Getters
|
||||
getCommentById: (threadId: string) => CommentSchema | undefined;
|
||||
// Getters
|
||||
getCommentById: (threadId: string) => CommentSchema | undefined;
|
||||
}
|
||||
|
||||
export const useCommentStore = create<CommentStore>()(
|
||||
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);
|
||||
},
|
||||
}))
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user