From a121401d0d2cd041b896343bfa2734d2c33fa7e9 Mon Sep 17 00:00:00 2001 From: "Alan Paul B. Paragas" Date: Mon, 12 Aug 2019 02:00:22 -0700 Subject: [PATCH] Bug Fix: Mounting Issue in Edit Article A fix to allow mounting of article content to the current state of the CreateArticle --- src/components/CreateArticle/index.jsx | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/components/CreateArticle/index.jsx b/src/components/CreateArticle/index.jsx index 849fa57..719c018 100644 --- a/src/components/CreateArticle/index.jsx +++ b/src/components/CreateArticle/index.jsx @@ -1,6 +1,7 @@ import React from 'react'; import PropTypes from 'prop-types'; import draftToHtml from 'draftjs-to-html'; +import htmlToDraft from 'html-to-draftjs'; import { EditorState, convertToRaw } from 'draft-js'; import CreateArticleForm from './CreateArticleForm'; @@ -31,13 +32,20 @@ class CreateArticle extends React.Component { } const categories = await this.props.getArticleCategories(); + + const blocksFromHtml = htmlToDraft(article.content); + const { contentBlocks, entityMap } = blocksFromHtml; + const contentState = ContentState.createFromBlockArray(contentBlocks, entityMap); + const editorState = EditorState.createWithContent(contentState); + + this.setState({ editing: true, article, categories, title: article.title, category: article.category_id, - content: article.content, + content: editorState, }); } else { const categories = await this.props.getArticleCategories();