import Inferno from 'inferno'; import Component from 'inferno-component'; import marked from 'marked'; import sanitizeHtml from 'sanitize-html'; import './styles.scss'; import { EditDictionaryModal } from '../../management/EditDictionaryModal'; import { DetailsSection } from './DetailsSection'; const DISPLAY = { NONE: false, DESCRIPTION: 1, DETAILS: 2, STATS: 3, } export class DictionaryDetails extends Component { constructor (props) { super(props); 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 = (

Stats!

); break; } } return (
{ displayJSX }
) } } render () { const { currentDisplay } = this.state; return (

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

{ this.displayInfo() }
); } }