From 0b6d510cc7aeae9e318a4d7157ecb75715762e9a Mon Sep 17 00:00:00 2001 From: Palanikannan1437 <73993394+Palanikannan1437@users.noreply.github.com> Date: Thu, 10 Aug 2023 01:20:15 +0530 Subject: [PATCH] added additional props and Tiptap Integration with Comments --- .../components/issues/comment/add-comment.tsx | 47 +++++++++++------- .../issues/comment/comment-card.tsx | 47 +++++++++++++----- .../components/issues/description-form.tsx | 4 ++ apps/app/components/issues/form.tsx | 1 + apps/app/components/issues/main-content.tsx | 48 +++++++++---------- 5 files changed, 96 insertions(+), 51 deletions(-) diff --git a/apps/app/components/issues/comment/add-comment.tsx b/apps/app/components/issues/comment/add-comment.tsx index 3b3cd21b0..157f56dce 100644 --- a/apps/app/components/issues/comment/add-comment.tsx +++ b/apps/app/components/issues/comment/add-comment.tsx @@ -1,7 +1,6 @@ import React from "react"; import { useRouter } from "next/router"; -import dynamic from "next/dynamic"; import { mutate } from "swr"; @@ -12,11 +11,12 @@ import issuesServices from "services/issues.service"; // hooks import useToast from "hooks/use-toast"; // ui -import { Loader, SecondaryButton } from "components/ui"; +import { SecondaryButton } from "components/ui"; // types import type { ICurrentUserResponse, IIssueComment } from "types"; // fetch-keys import { PROJECT_ISSUES_ACTIVITY } from "constants/fetch-keys"; +import Tiptap, { ITiptapRichTextEditor } from "components/tiptap"; // const RemirrorRichTextEditor = dynamic(() => import("components/rich-text-editor"), { // ssr: false, @@ -34,7 +34,14 @@ import { PROJECT_ISSUES_ACTIVITY } from "constants/fetch-keys"; // >((props, ref) => ); // // WrappedRemirrorRichTextEditor.displayName = "WrappedRemirrorRichTextEditor"; -// + +const TiptapEditor = React.forwardRef< + ITiptapRichTextEditor, + ITiptapRichTextEditor +>((props, ref) => ); + +TiptapEditor.displayName = "TiptapEditor"; + const defaultValues: Partial = { comment_json: "", comment_html: "", @@ -51,6 +58,7 @@ export const AddComment: React.FC = ({ issueId, user, disabled = false }) handleSubmit, control, setValue, + watch, formState: { isSubmitting }, reset, } = useForm({ defaultValues }); @@ -98,19 +106,26 @@ export const AddComment: React.FC = ({ issueId, user, disabled = false })
- {/* ( */} - {/* setValue("comment_json", jsonValue)} */} - {/* onHTMLChange={(htmlValue) => setValue("comment_html", htmlValue)} */} - {/* placeholder="Enter your comment..." */} - {/* ref={editorRef} */} - {/* /> */} - {/* )} */} - {/* /> */} + + { + onChange(comment_html); + setValue("comment_json", comment_json); + }} + /> + } + /> {isSubmitting ? "Adding..." : "Comment"} diff --git a/apps/app/components/issues/comment/comment-card.tsx b/apps/app/components/issues/comment/comment-card.tsx index 008290f43..10da0b74e 100644 --- a/apps/app/components/issues/comment/comment-card.tsx +++ b/apps/app/components/issues/comment/comment-card.tsx @@ -15,6 +15,7 @@ import { CommentReaction } from "components/issues"; import { timeAgo } from "helpers/date-time.helper"; // types import type { IIssueComment } from "types"; +import Tiptap, { ITiptapRichTextEditor } from "components/tiptap"; // const RemirrorRichTextEditor = dynamic(() => import("components/rich-text-editor"), { ssr: false }); // @@ -26,7 +27,14 @@ import type { IIssueComment } from "types"; // >((props, ref) => ); // // WrappedRemirrorRichTextEditor.displayName = "WrappedRemirrorRichTextEditor"; -// + +const TiptapEditor = React.forwardRef< + ITiptapRichTextEditor, + ITiptapRichTextEditor +>((props, ref) => ); + +TiptapEditor.displayName = "TiptapEditor"; + type Props = { comment: IIssueComment; onSubmit: (comment: IIssueComment) => void; @@ -45,6 +53,7 @@ export const CommentCard: React.FC = ({ comment, onSubmit, handleCommentD formState: { isSubmitting }, handleSubmit, setFocus, + watch, setValue, } = useForm({ defaultValues: comment, @@ -55,9 +64,10 @@ export const CommentCard: React.FC = ({ comment, onSubmit, handleCommentD setIsEditing(false); onSubmit(formData); + console.log("watching", formData.comment_html) - editorRef.current?.setEditorValue(formData.comment_json); - showEditorRef.current?.setEditorValue(formData.comment_json); + editorRef.current?.setEditorValue(formData.comment_html); + showEditorRef.current?.setEditorValue(formData.comment_html); }; useEffect(() => { @@ -105,14 +115,24 @@ export const CommentCard: React.FC = ({ comment, onSubmit, handleCommentD className={`flex-col gap-2 ${isEditing ? "flex" : "hidden"}`} onSubmit={handleSubmit(onEnter)} > - { - setValue("comment_json", jsonValue); - setValue("comment_html", htmlValue); - }} - placeholder="Enter Your comment..." + {/* { */} + {/* setValue("comment_json", jsonValue); */} + {/* setValue("comment_html", htmlValue); */} + {/* }} */} + {/* placeholder="Enter Your comment..." */} + {/* ref={editorRef} */} + {/* /> */} + { + setValue("comment_json", comment_json); + setValue("comment_html", comment_html); + }} />
+ {/* = ({ comment, onSubmit, handleCommentD {/* customClassName="text-xs border border-custom-border-200 bg-custom-background-100" */} {/* ref={showEditorRef} */} {/* /> */} -
diff --git a/apps/app/components/issues/description-form.tsx b/apps/app/components/issues/description-form.tsx index fcf10073d..1eb02915f 100644 --- a/apps/app/components/issues/description-form.tsx +++ b/apps/app/components/issues/description-form.tsx @@ -123,8 +123,12 @@ export const IssueDescriptionForm: FC = ({ ? watch("description_html") : value } + debouncedUpdatesEnabled={true} setIsSubmitting={setIsSubmitting} + customClassName="min-h-[150px]" + editorContentCustomClassNames="pt-9" onChange={(description: Object, description_html: string) => { + setIsSubmitting(true); onChange(description_html); setValue("description", description); handleSubmit(handleDescriptionFormSubmit)().finally(() => setIsSubmitting(false)); diff --git a/apps/app/components/issues/form.tsx b/apps/app/components/issues/form.tsx index 8d66edd21..8f71c8e53 100644 --- a/apps/app/components/issues/form.tsx +++ b/apps/app/components/issues/form.tsx @@ -372,6 +372,7 @@ export const IssueForm: FC = ({ return ( = ({ isAllowed={memberRole.isMember || memberRole.isOwner || !uneditable} /> - {/* */} - {/**/} - {/*
*/} - {/* */} - {/*
*/} - {/*
*/} - {/*
*/} - {/*

Attachments

*/} - {/*
*/} - {/* */} - {/* */} - {/*
*/} - {/*
*/} - {/*
*/} - {/*

Comments/Activity

*/} - {/* */} - {/* */} + + +
+ +
+
+
+

Attachments

+
+ + +
+
+
+

Comments/Activity

+ +
);