mirror of
https://github.com/makeplane/plane
synced 2024-06-14 14:31:34 +00:00
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:
parent
7842c4b2ea
commit
4447a4b519
@ -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"
|
||||||
|
@ -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, () => ({
|
||||||
|
@ -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, () => ({
|
||||||
|
Loading…
Reference in New Issue
Block a user