{
- // setShowAlert(true);
- // setValue("description", jsonValue);
- // }}
- // onHTMLChange={(htmlValue) => {
- // setShowAlert(true);
- // setValue("description_html", htmlValue);
- // }}
- // onBlur={() => {
- // setIsSubmitting(true);
- // handleSubmit(handleDescriptionFormSubmit)()
- // .then(() => setShowAlert(false))
- // .finally(() => setIsSubmitting(false));
- // }}
- // placeholder="Description"
- // editable={isAllowed}
- // />
);
}}
/>
- {isSubmitting && (
-
- Saving...
-
- )}
+
+ {isSubmitting ? "Saving..." : "Saved"}
+
);
diff --git a/apps/app/components/issues/tiptap.tsx b/apps/app/components/issues/tiptap.tsx
index 9e298ef3c..8909e4de1 100644
--- a/apps/app/components/issues/tiptap.tsx
+++ b/apps/app/components/issues/tiptap.tsx
@@ -1,6 +1,5 @@
-import Placeholder from '@tiptap/extension-placeholder';
import { useEditor, EditorContent } from '@tiptap/react';
-import StarterKit from '@tiptap/starter-kit';
+import { useDebouncedCallback } from 'use-debounce';
import { EditorBubbleMenu } from './EditorBubbleMenu';
import { TiptapExtensions } from './extensions';
import { TiptapEditorProps } from "./props";
@@ -10,21 +9,29 @@ type TiptapProps = {
noBorder?: boolean;
borderOnFocus?: boolean;
customClassName?: string;
+ onChange?: (json: any, html: string) => void;
+ setIsSubmitting?: (isSubmitting: boolean) => void;
}
-const Tiptap = ({ value, noBorder, borderOnFocus, customClassName }: TiptapProps) => {
+const Tiptap = ({ onChange, setIsSubmitting, value, noBorder, borderOnFocus, customClassName }: TiptapProps) => {
const editor = useEditor({
editorProps: TiptapEditorProps,
extensions: TiptapExtensions,
- // extensions: [
- // StarterKit,
- // Placeholder.configure({
- // placeholder: 'Description...',
- // })
- // ],
content: value,
+ onUpdate: async ({ editor }) => {
+ setIsSubmitting(true);
+ debouncedUpdates({ onChange, editor });
+ }
});
+ const debouncedUpdates = useDebouncedCallback(async ({ onChange, editor }) => {
+ setTimeout(async () => {
+ if (onChange) {
+ onChange(editor.getJSON(), editor.getHTML());
+ }
+ }, 500);
+ }, 1000);
+
const editorClassNames = `mt-2 p-3 relative focus:outline-none rounded-md focus:border-custom-border-200
${noBorder ? '' : 'border border-custom-border-200'
} ${borderOnFocus ? 'focus:border border-custom-border-200' : 'focus:border-0'