refactor: improve code readability and maintainability in MainScene, Messages, and ThreadChat components; adjust comments.scss for better layout
This commit is contained in:
@@ -212,7 +212,11 @@ function MainScene() {
|
||||
{activeModule !== "market" && !selectedUser && <Footer />}
|
||||
|
||||
<VersionSaved />
|
||||
{(commentPositionState !== null || selectedComment !== null) && <ThreadChat />}
|
||||
|
||||
{
|
||||
(commentPositionState !== null || selectedComment !== null) &&
|
||||
<ThreadChat />
|
||||
}
|
||||
|
||||
</>
|
||||
);
|
||||
|
||||
@@ -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>
|
||||
{(val as Reply).creatorId === userId && (
|
||||
<div className="more-options">
|
||||
<div
|
||||
className="more-options"
|
||||
onMouseLeave={() => setOpenOptions(false)}
|
||||
>
|
||||
<button
|
||||
className="more-options-button"
|
||||
onClick={() => {
|
||||
@@ -240,35 +243,41 @@ const Messages: React.FC<MessageProps> = ({ val, i, setMessages, mode, setIsEdit
|
||||
>
|
||||
<KebabIcon />
|
||||
</button>
|
||||
|
||||
{openOptions && (
|
||||
<div className="options-list">
|
||||
<button
|
||||
className="option"
|
||||
onClick={(e) => {
|
||||
e.preventDefault();
|
||||
setMode && setMode("edit")
|
||||
setMode && setMode("edit");
|
||||
setOpenOptions(false);
|
||||
setEditedThread && setEditedThread(true);
|
||||
setIsEditComment(true)
|
||||
setIsEditComment(true);
|
||||
}}
|
||||
>
|
||||
Edit
|
||||
</button>
|
||||
{!(isEditableThread) && <button
|
||||
className="option"
|
||||
onClick={() => {
|
||||
handleDeleteAction((val as Reply).replyId);
|
||||
}}
|
||||
>
|
||||
Delete
|
||||
</button>}
|
||||
|
||||
{!isEditableThread && (
|
||||
<button
|
||||
className="option"
|
||||
onClick={() => {
|
||||
handleDeleteAction((val as Reply).replyId);
|
||||
}}
|
||||
>
|
||||
Delete
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
|
||||
<div className="message">
|
||||
{"comment" in val ? val.comment : val.threadTitle}
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div >
|
||||
)}
|
||||
|
||||
@@ -131,9 +131,10 @@ const ThreadChat: React.FC = () => {
|
||||
if (dragging) updatePosition(e, true);
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
updatePosition({ clientX: position.x, clientY: position.y }, true);
|
||||
}, [selectedComment]);
|
||||
// Commented this useEffect to prevent offset after user saved the comment
|
||||
// useEffect(() => {
|
||||
// updatePosition({ clientX: position.x, clientY: position.y }, true);
|
||||
// }, [selectedComment]);
|
||||
|
||||
|
||||
const handlePointerUp = (event: React.PointerEvent<HTMLDivElement>) => {
|
||||
@@ -144,6 +145,10 @@ const ThreadChat: React.FC = () => {
|
||||
};
|
||||
|
||||
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();
|
||||
try {
|
||||
// const createComments = await addCommentsApi(projectId, value, selectedComment?.threadId, selectedVersion?.versionId || "")/
|
||||
@@ -163,6 +168,7 @@ const ThreadChat: React.FC = () => {
|
||||
|
||||
// }
|
||||
|
||||
|
||||
if (threadSocket && mode === "create") {
|
||||
const addComment = {
|
||||
versionId: selectedVersion?.versionId || "",
|
||||
@@ -190,7 +196,7 @@ const ThreadChat: React.FC = () => {
|
||||
// removeComment(selectedComment?.threadId)
|
||||
// setSelectedComment([])
|
||||
// }
|
||||
console.log('threadSocket:threadChat ', threadSocket);
|
||||
|
||||
if (threadSocket) {
|
||||
// projectId, userId, organization, threadId
|
||||
const deleteThread = {
|
||||
@@ -258,7 +264,7 @@ const ThreadChat: React.FC = () => {
|
||||
};
|
||||
|
||||
if (threadSocket) {
|
||||
console.log('createThread: ', createThread);
|
||||
|
||||
|
||||
setInputActive(false);
|
||||
threadSocket.emit("v1:thread:create", createThread);
|
||||
|
||||
@@ -171,8 +171,8 @@
|
||||
.messages-wrapper {
|
||||
padding: 12px;
|
||||
padding-top: 0;
|
||||
max-height: 50vh;
|
||||
overflow-y: auto;
|
||||
max-height: 36vh;
|
||||
overflow: auto;
|
||||
.edit-container {
|
||||
.input-container {
|
||||
textarea {
|
||||
|
||||
Reference in New Issue
Block a user