diff --git a/web/core/components/editor/lite-text-editor/toolbar.tsx b/web/core/components/editor/lite-text-editor/toolbar.tsx index 643095f1feb..de56890aca7 100644 --- a/web/core/components/editor/lite-text-editor/toolbar.tsx +++ b/web/core/components/editor/lite-text-editor/toolbar.tsx @@ -57,7 +57,6 @@ export const IssueCommentToolbar: React.FC = (props) => { showSubmitButton, editorRef, } = props; - // State to manage active states of toolbar items const [activeStates, setActiveStates] = useState>({}); @@ -86,6 +85,9 @@ export const IssueCommentToolbar: React.FC = (props) => { return () => unsubscribe(); }, [editorRef, updateActiveStates]); + const isEditorReadyToDiscard = editorRef?.isEditorReadyToDiscard(); + const isSubmitButtonDisabled = isCommentEmpty || !isEditorReadyToDiscard; + return (
{showAccessSpecifier && ( @@ -166,7 +168,7 @@ export const IssueCommentToolbar: React.FC = (props) => { variant="primary" className="px-2.5 py-1.5 text-xs" onClick={handleSubmit} - disabled={isCommentEmpty} + disabled={isSubmitButtonDisabled} loading={isSubmitting} > Comment diff --git a/web/core/components/issues/issue-detail/issue-activity/comments/comment-card.tsx b/web/core/components/issues/issue-detail/issue-activity/comments/comment-card.tsx index baae682881a..ec84304cb18 100644 --- a/web/core/components/issues/issue-detail/issue-activity/comments/comment-card.tsx +++ b/web/core/components/issues/issue-detail/issue-activity/comments/comment-card.tsx @@ -4,11 +4,16 @@ import { FC, useEffect, useRef, useState } from "react"; import { observer } from "mobx-react"; import { useForm } from "react-hook-form"; import { Check, Globe2, Lock, Pencil, Trash2, X } from "lucide-react"; +// plane constants import { EIssueCommentAccessSpecifier } from "@plane/constants"; +// plane editor import { EditorReadOnlyRefApi, EditorRefApi } from "@plane/editor"; +// plane types import { TIssueComment } from "@plane/types"; -// ui +// plane ui import { CustomMenu } from "@plane/ui"; +// plane utils +import { cn } from "@plane/utils"; // components import { LiteTextEditor, LiteTextReadOnlyEditor } from "@/components/editor"; // helpers @@ -42,21 +47,21 @@ export const IssueCommentCard: FC = observer((props) => { showAccessSpecifier = false, disabled = false, } = props; - // hooks + // states + const [isEditing, setIsEditing] = useState(false); + // refs + const editorRef = useRef(null); + const showEditorRef = useRef(null); + // store hooks const { comment: { getCommentById }, } = useIssueDetail(); const { data: currentUser } = useUser(); - // refs - const editorRef = useRef(null); - const showEditorRef = useRef(null); - // state - const [isEditing, setIsEditing] = useState(false); - + // derived values const comment = getCommentById(commentId); const workspaceStore = useWorkspace(); const workspaceId = workspaceStore.getWorkspaceBySlug(comment?.workspace_detail?.slug as string)?.id as string; - + // form info const { formState: { isSubmitting }, handleSubmit, @@ -66,6 +71,11 @@ export const IssueCommentCard: FC = observer((props) => { } = useForm>({ defaultValues: { comment_html: comment?.comment_html }, }); + // derived values + const commentHTML = watch("comment_html"); + const isEmpty = isCommentEmpty(commentHTML); + const isEditorReadyToDiscard = editorRef.current?.isEditorReadyToDiscard(); + const isSubmitButtonDisabled = isSubmitting || !isEditorReadyToDiscard; const onEnter = async (formData: Partial) => { if (isSubmitting || !comment) return; @@ -83,10 +93,8 @@ export const IssueCommentCard: FC = observer((props) => { } }, [isEditing, setFocus]); - const commentHTML = watch("comment_html"); - const isEmpty = isCommentEmpty(commentHTML); - if (!comment || !currentUser) return <>; + return ( = observer((props) => { {!disabled && currentUser?.id === comment.actor && ( setIsEditing(true)} className="flex items-center gap-1"> - - Edit comment + + Edit {showAccessSpecifier && ( <> @@ -107,7 +115,7 @@ export const IssueCommentCard: FC = observer((props) => { } className="flex items-center gap-1" > - + Switch to public comment ) : ( @@ -117,7 +125,7 @@ export const IssueCommentCard: FC = observer((props) => { } className="flex items-center gap-1" > - + Switch to private comment )} @@ -127,8 +135,8 @@ export const IssueCommentCard: FC = observer((props) => { onClick={() => activityOperations.removeComment(comment.id)} className="flex items-center gap-1" > - - Delete comment + + Delete )} @@ -166,24 +174,27 @@ export const IssueCommentCard: FC = observer((props) => { />
- + {!isEmpty && ( + + )}