2019-05-29 14:01:40 +00:00
|
|
|
import React from 'react';
|
|
|
|
import ReactMarkdown from 'react-markdown';
|
|
|
|
import { connect } from 'react-redux';
|
2019-06-22 22:08:02 +00:00
|
|
|
import { fetchPost } from '../actions';
|
2019-07-23 23:12:48 +00:00
|
|
|
import { Link } from 'react-router-dom';
|
2019-05-29 14:01:40 +00:00
|
|
|
|
|
|
|
class Post extends React.Component {
|
2019-07-26 21:41:32 +00:00
|
|
|
constructor (props) {
|
|
|
|
super(props)
|
|
|
|
this.state = {
|
|
|
|
isLoading: true
|
|
|
|
}
|
|
|
|
}
|
2019-05-29 14:01:40 +00:00
|
|
|
componentDidMount() {
|
2019-07-23 23:12:48 +00:00
|
|
|
const { slug } = this.props.match.params
|
2019-07-26 21:41:32 +00:00
|
|
|
this.props.fetchPost(slug)
|
|
|
|
.then(() => this.setState({isLoading: false}))
|
2019-05-29 14:01:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
render () {
|
2019-07-26 21:41:32 +00:00
|
|
|
const {posts} = this.props
|
|
|
|
const {isLoading} = this.state
|
|
|
|
|
|
|
|
if (isLoading) {
|
|
|
|
return <p>Loading</p>
|
|
|
|
} else {
|
|
|
|
const post = posts.entities[posts.currentId]
|
|
|
|
return (
|
|
|
|
<div className="item" key={post.id}>
|
|
|
|
<div className="content">
|
|
|
|
<div className="description">
|
|
|
|
<h1><b><u><Link to={"/posts/" + post.slug}>{post.title}</Link></u></b></h1>
|
2019-07-27 22:17:42 +00:00
|
|
|
<h3><b>By <Link to={"/users/"+ post.author}>{post.author}</Link></b></h3>
|
2019-07-26 21:41:32 +00:00
|
|
|
<ReactMarkdown source={post.content} />
|
|
|
|
</div>
|
2019-07-24 00:39:53 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
2019-07-26 21:41:32 +00:00
|
|
|
);
|
|
|
|
}
|
2019-05-29 14:01:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const mapStateToProps = (state) => {
|
2019-07-23 23:12:48 +00:00
|
|
|
return {
|
|
|
|
posts: state.posts,
|
|
|
|
slug: state.slug
|
|
|
|
};
|
2019-05-29 14:01:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export default connect(
|
|
|
|
mapStateToProps,
|
2019-07-23 23:12:48 +00:00
|
|
|
{ fetchPost }
|
2019-05-29 14:01:40 +00:00
|
|
|
)(Post);
|