fix: fix autosaving

This commit is contained in:
Kshitij Sobti
2021-12-03 18:28:37 +05:30
parent 0646d717ea
commit 4763702bd3
3 changed files with 7 additions and 1 deletions

View File

@@ -82,7 +82,6 @@ export default function TinyMCEEditor(props) {
a11y_advanced_options: true,
autosave_interval: '1s',
autosave_restore_when_empty: true,
autosave_prefix: 'tinymce-autosave-{path}{query}',
plugins: 'autosave codesample link lists image imagetools code',
toolbar: 'formatselect | bold italic underline'
+ ' | link blockquote openedx_code image'

View File

@@ -27,6 +27,9 @@ function CommentEditor({
}
onCloseEditor();
};
// 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.
const editorId = `comment-editor-${comment.id || comment.parentId || comment.threadId}`;
return (
<Formik
initialValues={{ comment: comment.rawBody }}
@@ -48,6 +51,7 @@ function CommentEditor({
<>
<Form onSubmit={handleSubmit}>
<TinyMCEEditor
id={editorId}
value={values.comment}
onEditorChange={formikCompatibleHandler(handleChange, 'comment')}
onBlur={formikCompatibleHandler(handleBlur, 'comment')}

View File

@@ -171,6 +171,8 @@ function PostEditor({
};
}
const postEditorId = `post-editor-${editExisting ? postId : 'new'}`;
return (
<Formik
enableReinitialize
@@ -302,6 +304,7 @@ function PostEditor({
</Form.Group>
<div className="py-2">
<TinyMCEEditor
id={postEditorId}
value={values.comment}
onEditorChange={formikCompatibleHandler(handleChange, 'comment')}
onBlur={formikCompatibleHandler(handleBlur, 'comment')}