+
sudoscientist:~#
- Users
Posts
About
diff --git a/src/components/Post.js b/src/components/Post.js
index e2c888e..3265260 100644
--- a/src/components/Post.js
+++ b/src/components/Post.js
@@ -30,6 +30,7 @@ class Post extends React.Component {
{post.title}
+ By {post.author}
diff --git a/src/components/PostList.js b/src/components/PostList.js
index d967a5f..9d48805 100644
--- a/src/components/PostList.js
+++ b/src/components/PostList.js
@@ -18,6 +18,7 @@ class PostList extends React.Component {
{post.title}
+ By {post.author}
diff --git a/src/components/User.js b/src/components/User.js
new file mode 100644
index 0000000..33d5b8b
--- /dev/null
+++ b/src/components/User.js
@@ -0,0 +1,51 @@
+import React from 'react';
+import { connect } from 'react-redux';
+import { fetchUserProfile } from '../actions';
+
+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}))
+ }
+
+ render () {
+ const {user} = this.props
+ const {isLoading} = this.state
+
+ if (isLoading) {
+ return
Loading
+ } else {
+ const currentUser = user.currentUser
+ return (
+
+
+
+
{currentUser.username}
+
Email: {currentUser.email}
+
Location: {currentUser.location}
+
About Me: {currentUser.bio}
+
+
+
+ );
+ }
+ }
+}
+
+const mapStateToProps = (state) => {
+ return {
+ user: state.user,
+ };
+}
+
+export default connect(
+ mapStateToProps,
+ { fetchUserProfile }
+)(User);
diff --git a/src/reducers/index.js b/src/reducers/index.js
index dad0a1a..fcc93a0 100644
--- a/src/reducers/index.js
+++ b/src/reducers/index.js
@@ -1,6 +1,8 @@
import { combineReducers } from 'redux';
import postsReducer from './postsReducer';
+import userReducer from './userReducer';
export default combineReducers({
- posts: postsReducer
+ posts: postsReducer,
+ user: userReducer
});
diff --git a/src/reducers/userReducer.js b/src/reducers/userReducer.js
new file mode 100644
index 0000000..153e729
--- /dev/null
+++ b/src/reducers/userReducer.js
@@ -0,0 +1,12 @@
+const initialState = {
+ currentUser: ""
+};
+
+export default (state = initialState, action) => {
+ switch (action.type) {
+ case 'FETCH_USER_PROFILE':
+ return {currentUser: action.payload}
+ default:
+ return state;
+ }
+};