fix: Tiptap comment card fix for space (#2129)

* fix:(space) fixed comment card's editor integration

* regression: removed content being set twice

* chore: added controller to manage tiptap editor

* chore: remove unused functions

---------

Co-authored-by: Aaryan Khandelwal <aaryankhandu123@gmail.com>
This commit is contained in:
M. Palanikannan 2023-09-11 12:54:19 +05:30 committed by GitHub
parent 7842c4b2ea
commit 4447a4b519
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 11 additions and 15 deletions

View File

@ -3,7 +3,7 @@ import React, { useState } from "react";
// mobx // mobx
import { observer } from "mobx-react-lite"; import { observer } from "mobx-react-lite";
// react-hook-form // react-hook-form
import { useForm, Controller } from "react-hook-form"; import { Controller, useForm } from "react-hook-form";
// headless ui // headless ui
import { Menu, Transition } from "@headlessui/react"; import { Menu, Transition } from "@headlessui/react";
// lib // lib
@ -30,10 +30,13 @@ export const CommentCard: React.FC<Props> = observer((props) => {
// states // states
const [isEditing, setIsEditing] = useState(false); const [isEditing, setIsEditing] = useState(false);
const editorRef = React.useRef<any>(null);
const showEditorRef = React.useRef<any>(null);
const { const {
control,
formState: { isSubmitting }, formState: { isSubmitting },
handleSubmit, handleSubmit,
control,
} = useForm<any>({ } = useForm<any>({
defaultValues: { comment_html: comment.comment_html }, defaultValues: { comment_html: comment.comment_html },
}); });
@ -47,6 +50,9 @@ export const CommentCard: React.FC<Props> = observer((props) => {
if (!workspaceSlug || !issueDetailStore.peekId) return; if (!workspaceSlug || !issueDetailStore.peekId) return;
issueDetailStore.updateIssueComment(workspaceSlug, comment.project, issueDetailStore.peekId, comment.id, formData); issueDetailStore.updateIssueComment(workspaceSlug, comment.project, issueDetailStore.peekId, comment.id, formData);
setIsEditing(false); setIsEditing(false);
editorRef.current?.setEditorValue(formData.comment_html);
showEditorRef.current?.setEditorValue(formData.comment_html);
}; };
return ( return (
@ -96,6 +102,7 @@ export const CommentCard: React.FC<Props> = observer((props) => {
render={({ field: { onChange, value } }) => ( render={({ field: { onChange, value } }) => (
<TipTapEditor <TipTapEditor
workspaceSlug={workspaceSlug as string} workspaceSlug={workspaceSlug as string}
ref={editorRef}
value={value} value={value}
debouncedUpdatesEnabled={false} debouncedUpdatesEnabled={false}
customClassName="min-h-[50px] p-3 shadow-sm" customClassName="min-h-[50px] p-3 shadow-sm"
@ -125,7 +132,8 @@ export const CommentCard: React.FC<Props> = observer((props) => {
</form> </form>
<div className={`${isEditing ? "hidden" : ""}`}> <div className={`${isEditing ? "hidden" : ""}`}>
<TipTapEditor <TipTapEditor
workspaceSlug={workspaceSlug.toString()} workspaceSlug={workspaceSlug as string}
ref={showEditorRef}
value={comment.comment_html} value={comment.comment_html}
editable={false} editable={false}
customClassName="text-xs border border-custom-border-200 bg-custom-background-100" customClassName="text-xs border border-custom-border-200 bg-custom-background-100"

View File

@ -56,12 +56,6 @@ const Tiptap = (props: ITipTapRichTextEditor) => {
}, },
}); });
useEffect(() => {
if (editor) {
editor.commands.setContent(value);
}
}, [value]);
const editorRef: React.MutableRefObject<Editor | null> = useRef(null); const editorRef: React.MutableRefObject<Editor | null> = useRef(null);
useImperativeHandle(forwardedRef, () => ({ useImperativeHandle(forwardedRef, () => ({

View File

@ -56,12 +56,6 @@ const Tiptap = (props: ITipTapRichTextEditor) => {
}, },
}); });
useEffect(() => {
if (editor) {
editor.commands.setContent(value);
}
}, [value]);
const editorRef: React.MutableRefObject<Editor | null> = useRef(null); const editorRef: React.MutableRefObject<Editor | null> = useRef(null);
useImperativeHandle(forwardedRef, () => ({ useImperativeHandle(forwardedRef, () => ({