Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import React, { useState } from "react";
// mobx
import { observer } from "mobx-react-lite";
// react-hook-form
import { useForm, Controller } from "react-hook-form";
import { Controller, useForm } from "react-hook-form";
// headless ui
import { Menu, Transition } from "@headlessui/react";
// lib
Expand All @@ -30,10 +30,13 @@ export const CommentCard: React.FC<Props> = observer((props) => {
// states
const [isEditing, setIsEditing] = useState(false);

const editorRef = React.useRef<any>(null);

const showEditorRef = React.useRef<any>(null);
const {
control,
formState: { isSubmitting },
handleSubmit,
control,
} = useForm<any>({
defaultValues: { comment_html: comment.comment_html },
});
Expand All @@ -47,6 +50,9 @@ export const CommentCard: React.FC<Props> = observer((props) => {
if (!workspaceSlug || !issueDetailStore.peekId) return;
issueDetailStore.updateIssueComment(workspaceSlug, comment.project, issueDetailStore.peekId, comment.id, formData);
setIsEditing(false);

editorRef.current?.setEditorValue(formData.comment_html);
showEditorRef.current?.setEditorValue(formData.comment_html);
};

return (
Expand Down Expand Up @@ -96,6 +102,7 @@ export const CommentCard: React.FC<Props> = observer((props) => {
render={({ field: { onChange, value } }) => (
<TipTapEditor
workspaceSlug={workspaceSlug as string}
ref={editorRef}
value={value}
debouncedUpdatesEnabled={false}
customClassName="min-h-[50px] p-3 shadow-sm"
Expand Down Expand Up @@ -125,7 +132,8 @@ export const CommentCard: React.FC<Props> = observer((props) => {
</form>
<div className={`${isEditing ? "hidden" : ""}`}>
<TipTapEditor
workspaceSlug={workspaceSlug.toString()}
workspaceSlug={workspaceSlug as string}
ref={showEditorRef}
value={comment.comment_html}
editable={false}
customClassName="text-xs border border-custom-border-200 bg-custom-background-100"
Expand Down
6 changes: 0 additions & 6 deletions space/components/tiptap/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,6 @@ const Tiptap = (props: ITipTapRichTextEditor) => {
},
});

useEffect(() => {
if (editor) {
editor.commands.setContent(value);
}
}, [value]);

const editorRef: React.MutableRefObject<Editor | null> = useRef(null);

useImperativeHandle(forwardedRef, () => ({
Expand Down
6 changes: 0 additions & 6 deletions web/components/tiptap/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,6 @@ const Tiptap = (props: ITipTapRichTextEditor) => {
},
});

useEffect(() => {
if (editor) {
editor.commands.setContent(value);
}
}, [value]);

const editorRef: React.MutableRefObject<Editor | null> = useRef(null);

useImperativeHandle(forwardedRef, () => ({
Expand Down