2019-07-27 22:17:42 +00:00
|
|
|
import React from 'react';
|
2019-07-27 23:48:59 +00:00
|
|
|
import ReactMarkdown from 'react-markdown';
|
2019-08-04 01:28:31 +00:00
|
|
|
import 'github-markdown-css'
|
2019-07-27 22:17:42 +00:00
|
|
|
import { connect } from 'react-redux';
|
|
|
|
import { fetchUserProfile } from '../actions';
|
2019-07-27 23:48:59 +00:00
|
|
|
import { Link } from 'react-router-dom';
|
2019-07-27 22:17:42 +00:00
|
|
|
|
|
|
|
class User extends React.Component {
|
|
|
|
constructor (props) {
|
|
|
|
super(props)
|
|
|
|
this.state = {
|
|
|
|
isLoading: true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
componentDidMount() {
|
|
|
|
const { user } = this.props.match.params
|
|
|
|
this.props.fetchUserProfile(user)
|
|
|
|
.then(() => this.setState({isLoading: false}))
|
|
|
|
}
|
2019-07-27 23:48:59 +00:00
|
|
|
renderList() {
|
|
|
|
const posts = this.props.user.currentUser.posts
|
|
|
|
return posts.map(post => {
|
|
|
|
return (
|
|
|
|
<div className="item" key={post.id}>
|
|
|
|
<div className="content">
|
|
|
|
<div className="description">
|
|
|
|
<h2><b><u><Link to={"/posts/" + post.slug}>{post.title}</Link></u></b></h2>
|
|
|
|
<h3><b>By <Link to={"/users/"+ post.author}>{post.author}</Link></b></h3>
|
2019-07-28 06:32:20 +00:00
|
|
|
<h4>Posted {post.time_published}</h4>
|
2019-08-04 01:28:31 +00:00
|
|
|
<div className="markdown-body">
|
|
|
|
<ReactMarkdown source={post.content} />
|
|
|
|
</div>
|
2019-07-27 23:48:59 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
});
|
|
|
|
}
|
2019-07-27 22:17:42 +00:00
|
|
|
|
|
|
|
render () {
|
|
|
|
const {user} = this.props
|
|
|
|
const {isLoading} = this.state
|
|
|
|
|
|
|
|
if (isLoading) {
|
|
|
|
return <p>Loading</p>
|
|
|
|
} else {
|
|
|
|
const currentUser = user.currentUser
|
|
|
|
return (
|
2019-07-27 23:48:59 +00:00
|
|
|
<div className="content">
|
|
|
|
<div className="item" key={currentUser.username}>
|
2019-07-27 22:17:42 +00:00
|
|
|
<div className="description">
|
2019-07-27 23:48:59 +00:00
|
|
|
<h1><b>This is the page of: {currentUser.username}</b></h1>
|
|
|
|
<h4><u>Email: {currentUser.email}</u></h4>
|
2019-07-27 22:17:42 +00:00
|
|
|
<div>Location: {currentUser.location}</div>
|
|
|
|
<div>About Me: {currentUser.bio}</div>
|
2019-07-27 23:48:59 +00:00
|
|
|
<div className="ui relaxed divided list">
|
|
|
|
{this.renderList()}
|
|
|
|
</div>
|
2019-07-27 22:17:42 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const mapStateToProps = (state) => {
|
|
|
|
return {
|
|
|
|
user: state.user,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
export default connect(
|
|
|
|
mapStateToProps,
|
|
|
|
{ fetchUserProfile }
|
|
|
|
)(User);
|