Enter key behaviour added for Comments

This commit is contained in:
Palanikannan1437 2023-10-03 19:51:23 +05:30
parent fc8284d458
commit ff29c1c87e
7 changed files with 25 additions and 15 deletions

View File

@ -1,12 +1,14 @@
import { Extension } from '@tiptap/core'; import { Extension } from '@tiptap/core';
export const EnterKeyExtension = Extension.create({ export const EnterKeyExtension = (onEnterKeyPress?: () => void) => Extension.create({
name: 'enterKey', name: 'enterKey',
addKeyboardShortcuts() { addKeyboardShortcuts() {
return { return {
'Enter': () => { 'Enter': () => {
console.log('Submit comment'); if (onEnterKeyPress) {
onEnterKeyPress();
}
return true; return true;
}, },
} }

View File

@ -1,5 +1,5 @@
import { EnterKeyExtension } from "./enter-key-extension"; import { EnterKeyExtension } from "./enter-key-extension";
export const LiteTextEditorExtensions = () => [ export const LiteTextEditorExtensions = (onEnterKeyPress?: () => void) => [
EnterKeyExtension, EnterKeyExtension(onEnterKeyPress),
]; ];

View File

@ -30,7 +30,8 @@ interface ILiteTextEditor {
key: string; key: string;
label: "Private" | "Public"; label: "Private" | "Public";
}[] }[]
} };
onEnterKeyPress?: (e?: any) => void;
} }
interface LiteTextEditorProps extends ILiteTextEditor { interface LiteTextEditorProps extends ILiteTextEditor {
@ -57,6 +58,7 @@ const LiteTextEditor = ({
customClassName, customClassName,
forwardedRef, forwardedRef,
commentAccessSpecifier, commentAccessSpecifier,
onEnterKeyPress
}: LiteTextEditorProps) => { }: LiteTextEditorProps) => {
const editor = useEditor({ const editor = useEditor({
onChange, onChange,
@ -68,7 +70,7 @@ const LiteTextEditor = ({
uploadFile, uploadFile,
deleteFile, deleteFile,
forwardedRef, forwardedRef,
extensions: LiteTextEditorExtensions(), extensions: LiteTextEditorExtensions(onEnterKeyPress),
}); });
const editorClassNames = getEditorClassNames({ noBorder, borderOnFocus, customClassName }); const editorClassNames = getEditorClassNames({ noBorder, borderOnFocus, customClassName });

View File

@ -11,7 +11,7 @@ import { SecondaryButton } from "components/ui";
// types // types
import { Comment } from "types/issue"; import { Comment } from "types/issue";
// components // components
import { RichTextEditorWithRef } from "@plane/rich-text-editor"; import { LiteTextEditorWithRef } from "@plane/lite-text-editor";
// service // service
import fileService from "@/services/file.service"; import fileService from "@/services/file.service";
@ -71,7 +71,12 @@ export const AddComment: React.FC<Props> = observer((props) => {
name="comment_html" name="comment_html"
control={control} control={control}
render={({ field: { value, onChange } }) => ( render={({ field: { value, onChange } }) => (
<RichTextEditorWithRef <LiteTextEditorWithRef
onEnterKeyPress={(e) => {
userStore.requiredLogin(() => {
handleSubmit(onSubmit)(e);
});
}}
uploadFile={fileService.getUploadFileFunction(workspace_slug as string)} uploadFile={fileService.getUploadFileFunction(workspace_slug as string)}
deleteFile={fileService.deleteImage} deleteFile={fileService.deleteImage}
ref={editorRef} ref={editorRef}

View File

@ -104,6 +104,7 @@ export const CommentCard: React.FC<Props> = observer((props) => {
name="comment_html" name="comment_html"
render={({ field: { onChange, value } }) => ( render={({ field: { onChange, value } }) => (
<LiteTextEditorWithRef <LiteTextEditorWithRef
onEnterKeyPress={handleSubmit(handleCommentUpdate)}
uploadFile={fileService.getUploadFileFunction(workspaceSlug)} uploadFile={fileService.getUploadFileFunction(workspaceSlug)}
deleteFile={fileService.deleteImage} deleteFile={fileService.deleteImage}
ref={editorRef} ref={editorRef}
@ -149,7 +150,7 @@ export const CommentCard: React.FC<Props> = observer((props) => {
<Menu as="div" className="relative w-min text-left"> <Menu as="div" className="relative w-min text-left">
<Menu.Button <Menu.Button
type="button" type="button"
onClick={() => {}} onClick={() => { }}
className="relative grid place-items-center rounded p-1 text-custom-text-200 hover:text-custom-text-100 outline-none cursor-pointer hover:bg-custom-background-80" className="relative grid place-items-center rounded p-1 text-custom-text-200 hover:text-custom-text-100 outline-none cursor-pointer hover:bg-custom-background-80"
> >
<EllipsisVerticalIcon className="h-5 w-5 text-custom-text-200 duration-300" /> <EllipsisVerticalIcon className="h-5 w-5 text-custom-text-200 duration-300" />
@ -173,9 +174,8 @@ export const CommentCard: React.FC<Props> = observer((props) => {
onClick={() => { onClick={() => {
setIsEditing(true); setIsEditing(true);
}} }}
className={`w-full select-none truncate rounded px-1 py-1.5 text-left text-custom-text-200 hover:bg-custom-background-80 ${ className={`w-full select-none truncate rounded px-1 py-1.5 text-left text-custom-text-200 hover:bg-custom-background-80 ${active ? "bg-custom-background-80" : ""
active ? "bg-custom-background-80" : "" }`}
}`}
> >
Edit Edit
</button> </button>
@ -188,9 +188,8 @@ export const CommentCard: React.FC<Props> = observer((props) => {
<button <button
type="button" type="button"
onClick={handleDelete} onClick={handleDelete}
className={`w-full select-none truncate rounded px-1 py-1.5 text-left text-custom-text-200 hover:bg-custom-background-80 ${ className={`w-full select-none truncate rounded px-1 py-1.5 text-left text-custom-text-200 hover:bg-custom-background-80 ${active ? "bg-custom-background-80" : ""
active ? "bg-custom-background-80" : "" }`}
}`}
> >
Delete Delete
</button> </button>

View File

@ -80,6 +80,7 @@ export const AddComment: React.FC<Props> = ({
control={control} control={control}
render={({ field: { onChange: onCommentChange, value: commentValue } }) => ( render={({ field: { onChange: onCommentChange, value: commentValue } }) => (
<LiteTextEditorWithRef <LiteTextEditorWithRef
onEnterKeyPress={handleSubmit(handleAddComment)}
uploadFile={fileService.getUploadFileFunction(workspaceSlug as string)} uploadFile={fileService.getUploadFileFunction(workspaceSlug as string)}
deleteFile={fileService.deleteImage} deleteFile={fileService.deleteImage}
ref={editorRef} ref={editorRef}

View File

@ -113,6 +113,7 @@ export const CommentCard: React.FC<Props> = ({
> >
<div> <div>
<LiteTextEditorWithRef <LiteTextEditorWithRef
onEnterKeyPress={handleSubmit(onEnter)}
uploadFile={fileService.getUploadFileFunction(workspaceSlug as string)} uploadFile={fileService.getUploadFileFunction(workspaceSlug as string)}
deleteFile={fileService.deleteImage} deleteFile={fileService.deleteImage}
ref={editorRef} ref={editorRef}