From 11e9ebcfd0eab98e4bfbe24f65136fd1fd365bbb Mon Sep 17 00:00:00 2001 From: Awais Ansari <79941147+awais-ansari@users.noreply.github.com> Date: Tue, 4 Oct 2022 18:58:50 +0500 Subject: [PATCH] fix: remove editor text persistence (#311) * fix: remove editor text persistence * fix: remove text persistence from comment/response editor * fix: stop comment/response validation on editor cancel button --- src/components/TinyMCEEditor.jsx | 2 +- .../comments/comment/CommentEditor.jsx | 12 ++- .../posts/post-editor/PostEditor.jsx | 90 ++++++++++--------- src/index.scss | 2 +- 4 files changed, 57 insertions(+), 49 deletions(-) diff --git a/src/components/TinyMCEEditor.jsx b/src/components/TinyMCEEditor.jsx index 75ca1fcb..793bdd8e 100644 --- a/src/components/TinyMCEEditor.jsx +++ b/src/components/TinyMCEEditor.jsx @@ -92,7 +92,7 @@ export default function TinyMCEEditor(props) { browser_spellcheck: true, a11y_advanced_options: true, autosave_interval: '1s', - autosave_restore_when_empty: true, + autosave_restore_when_empty: false, plugins: 'autosave codesample link lists image imagetools code emoticons charmap', toolbar: 'undo redo' + ' | formatselect | bold italic underline' diff --git a/src/discussions/comments/comment/CommentEditor.jsx b/src/discussions/comments/comment/CommentEditor.jsx index 0fec7c8a..60b965d4 100644 --- a/src/discussions/comments/comment/CommentEditor.jsx +++ b/src/discussions/comments/comment/CommentEditor.jsx @@ -54,7 +54,12 @@ function CommentEditor({ editReasonCode: comment?.lastEdit?.reasonCode || '', }; - const saveUpdatedComment = async (values) => { + const handleCloseEditor = (resetForm) => { + resetForm({ values: initialValues }); + onCloseEditor(); + }; + + const saveUpdatedComment = async (values, { resetForm }) => { if (comment.id) { const payload = { ...values, @@ -68,7 +73,7 @@ function CommentEditor({ if (editorRef.current) { editorRef.current.plugins.autosave.removeDraft(); } - onCloseEditor(); + handleCloseEditor(resetForm); }; // The editorId is used to autosave contents to localstorage. This format means that the autosave is scoped to // the current comment id, or the current comment parent or the curren thread. @@ -87,6 +92,7 @@ function CommentEditor({ handleSubmit, handleBlur, handleChange, + resetForm, }) => (