refactor: improve code readability and maintainability in MainScene, Messages, and ThreadChat components; adjust comments.scss for better layout

This commit is contained in:
Nalvazhuthi
2025-08-25 15:56:30 +05:30
parent d0ab679f3b
commit 5b7e8b893c
4 changed files with 38 additions and 19 deletions

View File

@@ -212,7 +212,11 @@ function MainScene() {
{activeModule !== "market" && !selectedUser && <Footer />} {activeModule !== "market" && !selectedUser && <Footer />}
<VersionSaved /> <VersionSaved />
{(commentPositionState !== null || selectedComment !== null) && <ThreadChat />}
{
(commentPositionState !== null || selectedComment !== null) &&
<ThreadChat />
}
</> </>
); );

View File

@@ -231,7 +231,10 @@ const Messages: React.FC<MessageProps> = ({ val, i, setMessages, mode, setIsEdit
<div className="time">{isEditableThread ? getRelativeTime(val.createdAt) : val.createdAt}</div> <div className="time">{isEditableThread ? getRelativeTime(val.createdAt) : val.createdAt}</div>
</div> </div>
{(val as Reply).creatorId === userId && ( {(val as Reply).creatorId === userId && (
<div className="more-options"> <div
className="more-options"
onMouseLeave={() => setOpenOptions(false)}
>
<button <button
className="more-options-button" className="more-options-button"
onClick={() => { onClick={() => {
@@ -240,35 +243,41 @@ const Messages: React.FC<MessageProps> = ({ val, i, setMessages, mode, setIsEdit
> >
<KebabIcon /> <KebabIcon />
</button> </button>
{openOptions && ( {openOptions && (
<div className="options-list"> <div className="options-list">
<button <button
className="option" className="option"
onClick={(e) => { onClick={(e) => {
e.preventDefault(); e.preventDefault();
setMode && setMode("edit") setMode && setMode("edit");
setOpenOptions(false); setOpenOptions(false);
setEditedThread && setEditedThread(true); setEditedThread && setEditedThread(true);
setIsEditComment(true) setIsEditComment(true);
}} }}
> >
Edit Edit
</button> </button>
{!(isEditableThread) && <button
{!isEditableThread && (
<button
className="option" className="option"
onClick={() => { onClick={() => {
handleDeleteAction((val as Reply).replyId); handleDeleteAction((val as Reply).replyId);
}} }}
> >
Delete Delete
</button>} </button>
)}
</div> </div>
)} )}
</div> </div>
)} )}
<div className="message"> <div className="message">
{"comment" in val ? val.comment : val.threadTitle} {"comment" in val ? val.comment : val.threadTitle}
</div> </div>
</div> </div>
</div > </div >
)} )}

View File

@@ -131,9 +131,10 @@ const ThreadChat: React.FC = () => {
if (dragging) updatePosition(e, true); if (dragging) updatePosition(e, true);
}; };
useEffect(() => { // Commented this useEffect to prevent offset after user saved the comment
updatePosition({ clientX: position.x, clientY: position.y }, true); // useEffect(() => {
}, [selectedComment]); // updatePosition({ clientX: position.x, clientY: position.y }, true);
// }, [selectedComment]);
const handlePointerUp = (event: React.PointerEvent<HTMLDivElement>) => { const handlePointerUp = (event: React.PointerEvent<HTMLDivElement>) => {
@@ -144,6 +145,10 @@ const ThreadChat: React.FC = () => {
}; };
const handleCreateComments = async (e: any) => { const handleCreateComments = async (e: any) => {
// Continue send or create message only there is only value avalibale
// To prevent empty value
if (!value) return;
e.preventDefault(); e.preventDefault();
try { try {
// const createComments = await addCommentsApi(projectId, value, selectedComment?.threadId, selectedVersion?.versionId || "")/ // const createComments = await addCommentsApi(projectId, value, selectedComment?.threadId, selectedVersion?.versionId || "")/
@@ -163,6 +168,7 @@ const ThreadChat: React.FC = () => {
// } // }
if (threadSocket && mode === "create") { if (threadSocket && mode === "create") {
const addComment = { const addComment = {
versionId: selectedVersion?.versionId || "", versionId: selectedVersion?.versionId || "",
@@ -190,7 +196,7 @@ const ThreadChat: React.FC = () => {
// removeComment(selectedComment?.threadId) // removeComment(selectedComment?.threadId)
// setSelectedComment([]) // setSelectedComment([])
// } // }
console.log('threadSocket:threadChat ', threadSocket);
if (threadSocket) { if (threadSocket) {
// projectId, userId, organization, threadId // projectId, userId, organization, threadId
const deleteThread = { const deleteThread = {
@@ -258,7 +264,7 @@ const ThreadChat: React.FC = () => {
}; };
if (threadSocket) { if (threadSocket) {
console.log('createThread: ', createThread);
setInputActive(false); setInputActive(false);
threadSocket.emit("v1:thread:create", createThread); threadSocket.emit("v1:thread:create", createThread);

View File

@@ -171,8 +171,8 @@
.messages-wrapper { .messages-wrapper {
padding: 12px; padding: 12px;
padding-top: 0; padding-top: 0;
max-height: 50vh; max-height: 36vh;
overflow-y: auto; overflow: auto;
.edit-container { .edit-container {
.input-container { .input-container {
textarea { textarea {