From 083562b24cf026d4084e4c77174e922e1bb65c5d Mon Sep 17 00:00:00 2001 From: Dakshesh Jain <65905942+dakshesh14@users.noreply.github.com> Date: Thu, 11 May 2023 13:41:16 +0530 Subject: [PATCH] fix: placeholder and ai response not getting appended in textarea (#1031) --- .../components/core/gpt-assistant-modal.tsx | 9 +++++++- .../components/issues/description-form.tsx | 18 ++------------- apps/app/components/issues/form.tsx | 23 +++++++++++++++---- apps/app/styles/editor.css | 7 +++--- 4 files changed, 32 insertions(+), 25 deletions(-) diff --git a/apps/app/components/core/gpt-assistant-modal.tsx b/apps/app/components/core/gpt-assistant-modal.tsx index f30d33616..90c558717 100644 --- a/apps/app/components/core/gpt-assistant-modal.tsx +++ b/apps/app/components/core/gpt-assistant-modal.tsx @@ -60,6 +60,8 @@ export const GptAssistantModal: React.FC = ({ const router = useRouter(); const { workspaceSlug } = router.query; + const editorRef = useRef(null); + const { setToastAlert } = useToast(); const { @@ -127,6 +129,10 @@ export const GptAssistantModal: React.FC = ({ if (isOpen) setFocus("task"); }, [isOpen, setFocus]); + useEffect(() => { + editorRef.current?.setEditorValue(htmlContent ?? `

${content}

`); + }, [htmlContent, editorRef, content]); + return (
= ({ {((content && content !== "") || (htmlContent && htmlContent !== "

")) && (
Content: - {content}

} customClassName="-m-3" noBorder borderOnFocus={false} editable={false} + ref={editorRef} />
)} diff --git a/apps/app/components/issues/description-form.tsx b/apps/app/components/issues/description-form.tsx index 679de126c..2a61e85a6 100644 --- a/apps/app/components/issues/description-form.tsx +++ b/apps/app/components/issues/description-form.tsx @@ -69,26 +69,12 @@ export const IssueDescriptionForm: FC = ({ issue, handleFormS [handleFormSubmit] ); - // useEffect(() => { - // const alertUser = (e: BeforeUnloadEvent) => { - // e.preventDefault(); - // e.returnValue = ""; - // return "Are you sure you want to leave?"; - // }; - - // window.addEventListener("beforeunload", alertUser); - // return () => { - // window.removeEventListener("beforeunload", alertUser); - // }; - // }, [isSubmitting]); - // reset form values useEffect(() => { if (!issue) return; reset({ ...issue, - description: issue.description, }); }, [issue, reset]); @@ -139,7 +125,7 @@ export const IssueDescriptionForm: FC = ({ issue, handleFormS name="description" control={control} render={({ field: { value } }) => { - if (!value || !watch("description_html")) return <>; + if (!value && !watch("description_html")) return <>; return ( = ({ issue, handleFormS setIsSubmitting(false); }); }} - placeholder="Describe the issue..." + placeholder="Description" editable={!isNotAllowed} /> ); diff --git a/apps/app/components/issues/form.tsx b/apps/app/components/issues/form.tsx index e6871dc36..ddda21ef4 100644 --- a/apps/app/components/issues/form.tsx +++ b/apps/app/components/issues/form.tsx @@ -1,4 +1,4 @@ -import { ChangeEvent, FC, useState, useEffect } from "react"; +import React, { ChangeEvent, FC, useState, useEffect, useRef } from "react"; import Link from "next/link"; import dynamic from "next/dynamic"; @@ -50,6 +50,15 @@ const RemirrorRichTextEditor = dynamic(() => import("components/rich-text-editor ), }); +import { IRemirrorRichTextEditor } from "components/rich-text-editor"; + +const WrappedRemirrorRichTextEditor = React.forwardRef< + IRemirrorRichTextEditor, + IRemirrorRichTextEditor +>((props, ref) => ); + +WrappedRemirrorRichTextEditor.displayName = "WrappedRemirrorRichTextEditor"; + const defaultValues: Partial = { project: "", name: "", @@ -105,6 +114,8 @@ export const IssueForm: FC = ({ const [gptAssistantModal, setGptAssistantModal] = useState(false); const [iAmFeelingLucky, setIAmFeelingLucky] = useState(false); + const editorRef = useRef(null); + const router = useRouter(); const { workspaceSlug } = router.query; @@ -346,7 +357,7 @@ export const IssueForm: FC = ({ name="description" control={control} render={({ field: { value } }) => ( - = ({ } onJSONChange={(jsonValue) => setValue("description", jsonValue)} onHTMLChange={(htmlValue) => setValue("description_html", htmlValue)} - placeholder="Describe the issue..." + placeholder="Description" + ref={editorRef} /> )} /> @@ -368,7 +380,10 @@ export const IssueForm: FC = ({ inset="top-2 left-0" content="" htmlContent={watch("description_html")} - onResponse={handleAiAssistance} + onResponse={(response) => { + handleAiAssistance(response); + editorRef.current?.setEditorValue(`${watch("description_html")}`); + }} projectId={projectId} />
diff --git a/apps/app/styles/editor.css b/apps/app/styles/editor.css index c177dad6c..418ed9d1d 100644 --- a/apps/app/styles/editor.css +++ b/apps/app/styles/editor.css @@ -1,13 +1,11 @@ .empty-node::after { content: attr(data-placeholder); - color: #ccc; - font-style: italic; + color: #9ca3af; position: absolute; pointer-events: none; top: 15px; margin-left: 1px; - z-index: -1; } .ProseMirror { @@ -92,6 +90,7 @@ fill: rgb(var(--color-text-base)) !important; } -.MuiButtonBase-root.Mui-selected, .MuiButtonBase-root:hover { +.MuiButtonBase-root.Mui-selected, +.MuiButtonBase-root:hover { background-color: rgb(var(--color-bg-base)) !important; }