File size: 2,594 Bytes
1e92f2d |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
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 (
<div className="article-page">
<div className="banner">
<div className="container">
<h1>{this.props.article.title}</h1>
<ArticleMeta
article={this.props.article}
canModify={canModify} />
</div>
</div>
<div className="container page">
<div className="row article-content">
<div className="col-xs-12">
<div dangerouslySetInnerHTML={markup}></div>
<ul className="tag-list">
{
this.props.article.tagList.map(tag => {
return (
<li
className="tag-default tag-pill tag-outline"
key={tag}>
{tag}
</li>
);
})
}
</ul>
</div>
</div>
<hr />
<div className="article-actions">
</div>
<div className="row">
<CommentContainer
comments={this.props.comments || []}
errors={this.props.commentErrors}
slug={this.props.match.params.id}
currentUser={this.props.currentUser} />
</div>
</div>
</div>
);
}
}
export default connect(mapStateToProps, mapDispatchToProps)(Article);
|