@@ -8,6 +8,7 @@ import Container from '../common/Container';
88import * as config from '../config' ;
99import { StyleRulesCallback } from '@material-ui/core/styles/withStyles' ;
1010import ReactMarkdown from 'react-markdown' ;
11+ import { RenderMode , contentType } from './extras' ;
1112
1213const styles : StyleRulesCallback = ( ) => ( {
1314 header : {
@@ -53,6 +54,7 @@ interface IProps {
5354 date : string ;
5455 content : string ;
5556 fDelete : VoidFunction ;
57+ extras ?: IMessageExtras ;
5658 height : ( height : number ) => void ;
5759}
5860
@@ -62,8 +64,20 @@ class Message extends React.PureComponent<IProps & WithStyles<typeof styles>> {
6264 public componentDidMount = ( ) =>
6365 this . props . height ( this . node ? this . node . getBoundingClientRect ( ) . height : 0 ) ;
6466
67+ private renderContent = ( ) => {
68+ const content = this . props . content ;
69+ switch ( contentType ( this . props . extras ) ) {
70+ case RenderMode . Markdown :
71+ return < ReactMarkdown source = { content } escapeHtml = { true } /> ;
72+ case RenderMode . Plain :
73+ default :
74+ return content ;
75+ }
76+ } ;
77+
6578 public render ( ) : React . ReactNode {
66- const { fDelete, classes, title, date, content, image} = this . props ;
79+ const { fDelete, classes, title, date, image} = this . props ;
80+
6781 return (
6882 < div className = { `${ classes . wrapperPadding } message` } ref = { ( ref ) => ( this . node = ref ) } >
6983 < Container style = { { display : 'flex' } } >
@@ -93,7 +107,7 @@ class Message extends React.PureComponent<IProps & WithStyles<typeof styles>> {
93107 </ IconButton >
94108 </ div >
95109 < Typography component = "div" className = { `${ classes . content } content` } >
96- < ReactMarkdown source = { content } escapeHtml = { true } />
110+ { this . renderContent ( ) }
97111 </ Typography >
98112 </ div >
99113 </ Container >
0 commit comments