fix: placeholder and ai response not getting appended in textarea (#1031)

This commit is contained in:
Dakshesh Jain 2023-05-11 13:41:16 +05:30 committed by GitHub
parent 88d3fa549a
commit 083562b24c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 32 additions and 25 deletions

View File

@ -60,6 +60,8 @@ export const GptAssistantModal: React.FC<Props> = ({
const router = useRouter(); const router = useRouter();
const { workspaceSlug } = router.query; const { workspaceSlug } = router.query;
const editorRef = useRef<any>(null);
const { setToastAlert } = useToast(); const { setToastAlert } = useToast();
const { const {
@ -127,6 +129,10 @@ export const GptAssistantModal: React.FC<Props> = ({
if (isOpen) setFocus("task"); if (isOpen) setFocus("task");
}, [isOpen, setFocus]); }, [isOpen, setFocus]);
useEffect(() => {
editorRef.current?.setEditorValue(htmlContent ?? `<p>${content}</p>`);
}, [htmlContent, editorRef, content]);
return ( return (
<div <div
className={`absolute ${inset} z-20 w-full space-y-4 rounded-[10px] border border-brand-base bg-brand-base p-4 shadow ${ className={`absolute ${inset} z-20 w-full space-y-4 rounded-[10px] border border-brand-base bg-brand-base p-4 shadow ${
@ -136,12 +142,13 @@ export const GptAssistantModal: React.FC<Props> = ({
{((content && content !== "") || (htmlContent && htmlContent !== "<p></p>")) && ( {((content && content !== "") || (htmlContent && htmlContent !== "<p></p>")) && (
<div className="remirror-section text-sm"> <div className="remirror-section text-sm">
Content: Content:
<RemirrorRichTextEditor <WrappedRemirrorRichTextEditor
value={htmlContent ?? <p>{content}</p>} value={htmlContent ?? <p>{content}</p>}
customClassName="-m-3" customClassName="-m-3"
noBorder noBorder
borderOnFocus={false} borderOnFocus={false}
editable={false} editable={false}
ref={editorRef}
/> />
</div> </div>
)} )}

View File

@ -69,26 +69,12 @@ export const IssueDescriptionForm: FC<IssueDetailsProps> = ({ issue, handleFormS
[handleFormSubmit] [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 // reset form values
useEffect(() => { useEffect(() => {
if (!issue) return; if (!issue) return;
reset({ reset({
...issue, ...issue,
description: issue.description,
}); });
}, [issue, reset]); }, [issue, reset]);
@ -139,7 +125,7 @@ export const IssueDescriptionForm: FC<IssueDetailsProps> = ({ issue, handleFormS
name="description" name="description"
control={control} control={control}
render={({ field: { value } }) => { render={({ field: { value } }) => {
if (!value || !watch("description_html")) return <></>; if (!value && !watch("description_html")) return <></>;
return ( return (
<RemirrorRichTextEditor <RemirrorRichTextEditor
@ -169,7 +155,7 @@ export const IssueDescriptionForm: FC<IssueDetailsProps> = ({ issue, handleFormS
setIsSubmitting(false); setIsSubmitting(false);
}); });
}} }}
placeholder="Describe the issue..." placeholder="Description"
editable={!isNotAllowed} editable={!isNotAllowed}
/> />
); );

View File

@ -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 Link from "next/link";
import dynamic from "next/dynamic"; 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) => <RemirrorRichTextEditor {...props} forwardedRef={ref} />);
WrappedRemirrorRichTextEditor.displayName = "WrappedRemirrorRichTextEditor";
const defaultValues: Partial<IIssue> = { const defaultValues: Partial<IIssue> = {
project: "", project: "",
name: "", name: "",
@ -105,6 +114,8 @@ export const IssueForm: FC<IssueFormProps> = ({
const [gptAssistantModal, setGptAssistantModal] = useState(false); const [gptAssistantModal, setGptAssistantModal] = useState(false);
const [iAmFeelingLucky, setIAmFeelingLucky] = useState(false); const [iAmFeelingLucky, setIAmFeelingLucky] = useState(false);
const editorRef = useRef<any>(null);
const router = useRouter(); const router = useRouter();
const { workspaceSlug } = router.query; const { workspaceSlug } = router.query;
@ -346,7 +357,7 @@ export const IssueForm: FC<IssueFormProps> = ({
name="description" name="description"
control={control} control={control}
render={({ field: { value } }) => ( render={({ field: { value } }) => (
<RemirrorRichTextEditor <WrappedRemirrorRichTextEditor
value={ value={
!value || (typeof value === "object" && Object.keys(value).length === 0) !value || (typeof value === "object" && Object.keys(value).length === 0)
? watch("description_html") ? watch("description_html")
@ -354,7 +365,8 @@ export const IssueForm: FC<IssueFormProps> = ({
} }
onJSONChange={(jsonValue) => setValue("description", jsonValue)} onJSONChange={(jsonValue) => setValue("description", jsonValue)}
onHTMLChange={(htmlValue) => setValue("description_html", htmlValue)} onHTMLChange={(htmlValue) => setValue("description_html", htmlValue)}
placeholder="Describe the issue..." placeholder="Description"
ref={editorRef}
/> />
)} )}
/> />
@ -368,7 +380,10 @@ export const IssueForm: FC<IssueFormProps> = ({
inset="top-2 left-0" inset="top-2 left-0"
content="" content=""
htmlContent={watch("description_html")} htmlContent={watch("description_html")}
onResponse={handleAiAssistance} onResponse={(response) => {
handleAiAssistance(response);
editorRef.current?.setEditorValue(`${watch("description_html")}`);
}}
projectId={projectId} projectId={projectId}
/> />
</div> </div>

View File

@ -1,13 +1,11 @@
.empty-node::after { .empty-node::after {
content: attr(data-placeholder); content: attr(data-placeholder);
color: #ccc; color: #9ca3af;
font-style: italic;
position: absolute; position: absolute;
pointer-events: none; pointer-events: none;
top: 15px; top: 15px;
margin-left: 1px; margin-left: 1px;
z-index: -1;
} }
.ProseMirror { .ProseMirror {
@ -92,6 +90,7 @@
fill: rgb(var(--color-text-base)) !important; 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; background-color: rgb(var(--color-bg-base)) !important;
} }