From b8ad8a78c98fc4022b8b695ecf284ce5c506f1ee Mon Sep 17 00:00:00 2001 From: Aaryan Khandelwal Date: Mon, 5 Dec 2022 11:12:21 +0530 Subject: [PATCH] fix: lexical --- apps/app/components/lexical/editor.tsx | 24 ++++++++++++++----- apps/app/components/lexical/helpers/editor.ts | 10 ++++---- .../issues/CreateUpdateIssueModal/index.tsx | 3 +-- .../project/issues/ListView/index.tsx | 4 ++-- 4 files changed, 25 insertions(+), 16 deletions(-) diff --git a/apps/app/components/lexical/editor.tsx b/apps/app/components/lexical/editor.tsx index e7cd68033..982bd7490 100644 --- a/apps/app/components/lexical/editor.tsx +++ b/apps/app/components/lexical/editor.tsx @@ -1,4 +1,10 @@ -import { EditorState, LexicalEditor, $getRoot, $getSelection } from "lexical"; +import { + EditorState, + $getRoot, + $getSelection, + SerializedEditorState, + LexicalEditor, +} from "lexical"; import { LexicalComposer } from "@lexical/react/LexicalComposer"; import { ContentEditable } from "@lexical/react/LexicalContentEditable"; import { RichTextPlugin } from "@lexical/react/LexicalRichTextPlugin"; @@ -21,7 +27,7 @@ import { getValidatedValue } from "./helpers/editor"; import LexicalErrorBoundary from "@lexical/react/LexicalErrorBoundary"; export interface RichTextEditorProps { - onChange: (state: string) => void; + onChange: (state: SerializedEditorState) => void; id: string; value: string; placeholder?: string; @@ -33,11 +39,17 @@ const RichTextEditor: React.FC = ({ value, placeholder = "Enter some text...", }) => { - function handleChange(state: EditorState, editor: LexicalEditor) { - state.read(() => { - onChange(JSON.stringify(state.toJSON())); + const handleChange = (editorState: EditorState) => { + editorState.read(() => { + let editorData = editorState.toJSON(); + if (onChange) onChange(editorData); }); - } + }; + // function handleChange(state: EditorState, editor: LexicalEditor) { + // state.read(() => { + // onChange(state.toJSON()); + // }); + // } return ( { editor.style.left = "-1000px"; } else { editor.style.opacity = "1"; - editor.style.top = `${ - rect.top + rect.height + window.pageYOffset + 10 - }px`; + editor.style.top = `${rect.top + rect.height + window.pageYOffset + 10}px`; editor.style.left = `${ rect.left + window.pageXOffset - editor.offsetWidth / 2 + rect.width / 2 }px`; @@ -22,9 +20,9 @@ export const getValidatedValue = (value: string) => { if (value) { try { - const json = JSON.parse(value); - return JSON.stringify(json); - } catch (error) { + console.log(value); + return value; + } catch (e) { return defaultValue; } } diff --git a/apps/app/components/project/issues/CreateUpdateIssueModal/index.tsx b/apps/app/components/project/issues/CreateUpdateIssueModal/index.tsx index d9e3110b3..f4cec947c 100644 --- a/apps/app/components/project/issues/CreateUpdateIssueModal/index.tsx +++ b/apps/app/components/project/issues/CreateUpdateIssueModal/index.tsx @@ -51,7 +51,7 @@ type Props = { const defaultValues: Partial = { project: "", name: "", - description: "", + // description: "", state: "", sprints: "", priority: "", @@ -176,7 +176,6 @@ const CreateUpdateIssuesModal: React.FC = ({ if (!activeWorkspace || !activeProject) return; const payload: Partial = { ...formData, - description: JSON.stringify(formData.description), target_date: formData.target_date ? renderDateFormat(formData.target_date ?? "") : null, }; if (!data) { diff --git a/apps/app/components/project/issues/ListView/index.tsx b/apps/app/components/project/issues/ListView/index.tsx index c4f1633d0..033e060d2 100644 --- a/apps/app/components/project/issues/ListView/index.tsx +++ b/apps/app/components/project/issues/ListView/index.tsx @@ -184,9 +184,9 @@ const ListView: React.FC = ({ {/* */} - {issue.description} + {/* {issue.description} */} ) : (key as keyof Properties) === "priority" ? (