<commit_before>import React, { Component } from 'react'
import PropTypes from 'prop-types'
import { EditorState, convertToRaw, ContentState, convertFromHTML } from 'draft-js'
import { Editor } from 'react-draft-wysiwyg'
import draftToHtml from 'draftjs-to-html'

import 'react-draft-wysiwyg/dist/react-draft-wysiwyg.css'

class WYSIWYG extends Component {
  static propTypes = {
    value: PropTypes.string.isRequired,
    onChange: PropTypes.func.isRequired,
  }
  
  constructor(props) {
    super(props)
    
    this.state = {
      editorState: this.convertHtmlToEditorState(this.props.value),
    }
    
    this.onEditorStateChange = this.onEditorStateChange.bind(this)
  }
  
  convertHtmlToEditorState() {
    const { value } = this.props
    const blocksFromHTML = convertFromHTML(value)
    const state = ContentState.createFromBlockArray(
      blocksFromHTML.contentBlocks,
      blocksFromHTML.entityMap
    )
    
    return EditorState.createWithContent(state)
  }
  
  onEditorStateChange(editorState) {
    this.setState({
      editorState,
    })
    
    this.props.onChange(draftToHtml(convertToRaw(editorState.getCurrentContent())))
  }
  
  render() {<commit_msg>fix #9 new article page is not working due to null state<commit_after>import React, { Component } from 'react'
import PropTypes from 'prop-types'
import { EditorState, convertToRaw, ContentState, convertFromHTML } from 'draft-js'
import { Editor } from 'react-draft-wysiwyg'
import draftToHtml from 'draftjs-to-html'

import 'react-draft-wysiwyg/dist/react-draft-wysiwyg.css'

class WYSIWYG extends Component {
  static propTypes = {
    value: PropTypes.string.isRequired,
    onChange: PropTypes.func.isRequired,
  }

  constructor(props) {
    super(props)

    this.state = {
      editorState: this.convertHtmlToEditorState(this.props.value),
    }

    this.onEditorStateChange = this.onEditorStateChange.bind(this)
  }

  convertHtmlToEditorState(value) {
    if (value){
      const blocksFromHTML = convertFromHTML(value)
      const state = ContentState.createFromBlockArray(
        blocksFromHTML.contentBlocks,
        blocksFromHTML.entityMap
      )

      return EditorState.createWithContent(state)
    }
  }

  onEditorStateChange(editorState) {
    this.setState({
      editorState,
    })

    this.props.onChange(draftToHtml(convertToRaw(editorState.getCurrentContent())))
  }

  render() {
{'fraction_non_alphanumeric': 0.09879116298457691, 'fraction_numerical': 0.00041684035014589413, 'mean_word_length': 3.7244094488188977, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1455221', 'n_tokens_mistral': 742, 'n_tokens_neox': 745, 'n_words': 134}