import ArticleMeta from './ArticleMeta'; import CommentContainer from './CommentContainer'; import React from 'react'; import agent from '../../agent'; import { connect } from 'react-redux'; import marked from 'marked'; import { ARTICLE_PAGE_LOADED, ARTICLE_PAGE_UNLOADED } from '../../constants/actionTypes'; const mapStateToProps = state => ({ ...state.article, currentUser: state.common.currentUser }); const mapDispatchToProps = dispatch => ({ onLoad: payload => dispatch({ type: ARTICLE_PAGE_LOADED, payload }), onUnload: () => dispatch({ type: ARTICLE_PAGE_UNLOADED }) }); class Article extends React.Component { componentWillMount() { this.props.onLoad(Promise.all([ agent.Articles.get(this.props.match.params.id), agent.Comments.forArticle(this.props.match.params.id) ])); } componentWillUnmount() { this.props.onUnload(); } render() { if (!this.props.article) { return null; } const markup = { __html: marked(this.props.article.body, { sanitize: true }) }; const canModify = this.props.currentUser && this.props.currentUser.username === this.props.article.author.username; return (

{this.props.article.title}

    { this.props.article.tagList.map(tag => { return (
  • {tag}
  • ); }) }

); } } export default connect(mapStateToProps, mapDispatchToProps)(Article);