/*
 * @Description: 代码预览页面
 * @Author: tangjiang
 * @Github:
 * @Date: 2019-11-24 10:09:55
 * @LastEditors: tangjiang
 * @LastEditTime: 2019-12-18 10:02:24
 */
import './index.scss';
import React, { useEffect, useState, useRef } from 'react';
import { connect } from 'react-redux';
import { Empty } from 'antd';
import RenderHtml from '../../../../../components/render-html'

const PrevTab = (props) => {

  const prevRef = useRef(null);
  const [renderCtx, setRenderCtx] = useState(() => '');

  // 渲染内容
  useEffect(() => {
    if (props.description) {
      setRenderCtx(() => (
        <div
          id="quill_editor"
          style={{ height: '100%', width: '100%' }}
          ref={prevRef}>
          <RenderHtml style={{ wordBreak: "break-word", fontWeight: "bold" }} value={props.description} />
        </div>
      ));
    } else {
      setRenderCtx(() => (
        <div className='no_result'>
          <Empty />
        </div>
      ));
    }
  }, [props]);

  return (
    <div className={`prev_area`}>
      {renderCtx}
    </div>
  )

}
const mapStateToProps = (state) => {
  const { ojForm } = state.ojFormReducer;
  return {
    description: ojForm.description
  }
}

export default connect(
  mapStateToProps
)(PrevTab);