import Inferno from 'inferno'; import { Component } from 'inferno'; import PropTypes from 'prop-types'; import marked from 'marked'; import sanitizeHtml from 'sanitize-html'; import './styles.scss'; import { EditDictionaryModal } from '../../management/EditDictionaryModal'; import { DetailsSection } from './DetailsSection'; import { StatsSection } from './StatsSection'; const DISPLAY = { NONE: false, DESCRIPTION: 1, DETAILS: 2, STATS: 3, } export class DictionaryDetails extends Component { constructor (props) { super(props); PropTypes.checkPropTypes({ name: PropTypes.string, specification: PropTypes.string, description: PropTypes.string, partsOfSpeech: PropTypes.array, alphabeticalOrder: PropTypes.array, details: PropTypes.object, settings: PropTypes.object, stats: PropTypes.object, updater: PropTypes.object, updateDisplay: PropTypes.func, }, props, 'prop', 'DictionaryDetails'); this.state = { currentDisplay: DISPLAY.NONE, } this._descriptionHTML = marked(sanitizeHtml(props.description, { allowedTags: [], allowedAttributes: [], })); } componentWillReceiveProps (nextProps) { const currentDescription = this.props.description, nextDescription = nextProps.description; if (currentDescription !== nextDescription) { this._descriptionHTML = marked(sanitizeHtml(nextProps.description, { allowedTags: [], allowedAttributes: [], })); } } toggleDisplay (display) { display = (this.state.currentDisplay !== display) ? display : DISPLAY.NONE; this.setState({ currentDisplay: display, }); } displayInfo () { if (this.state.currentDisplay !== DISPLAY.NONE) { let displayJSX; switch(this.state.currentDisplay) { case DISPLAY.DESCRIPTION : { // Not sure why, but the dangerouslySet div needs to be wrapped in another div or else // the HTML content sticks around for some reason. displayJSX = (
); break; } case DISPLAY.DETAILS : { displayJSX = ( ); break; } case DISPLAY.STATS : { displayJSX = ( ); break; } } return (
{ displayJSX }
) } } render () { const { currentDisplay } = this.state; return (

{ this.props.name } { this.props.specification }

{ this.displayInfo() }
); } }