diff --git a/src/actions/index.js b/src/actions/index.js
index 1293557..cbc73e8 100644
--- a/src/actions/index.js
+++ b/src/actions/index.js
@@ -11,11 +11,9 @@ export const fetchPost = (slug) => async (dispatch) => {
};
export const fetchUserProfile = (user) => async (dispatch) => {
- const response = await sudoscientist.get('/users/' + user);
- dispatch({ type: 'FETCH_USER_PROFILE', payload: response.data })
-};
-
-export const fetchUserPosts = (user) => async (dispatch) => {
- const response = await sudoscientist.get('/blog/by-author/' + user);
- dispatch({ type: 'FETCH_USER_POSTS', payload: response.data })
+ const profile = await sudoscientist.get('/users/' + user);
+ const userPosts = await sudoscientist.get('/blog/by-author/' + user);
+ const test = {posts: userPosts.data}
+ const response = { ...profile.data, ...test }
+ dispatch({ type: 'FETCH_USER', payload: response })
};
diff --git a/src/components/PostList.js b/src/components/PostList.js
index 9d48805..c028409 100644
--- a/src/components/PostList.js
+++ b/src/components/PostList.js
@@ -4,6 +4,7 @@ import { connect } from 'react-redux';
import { fetchPosts } from '../actions';
import { Link } from 'react-router-dom';
+
class PostList extends React.Component {
componentDidMount() {
this.props.fetchPosts();
@@ -15,16 +16,17 @@ class PostList extends React.Component {
const post = posts.entities[id]
return (
+
Blog Posts
-
{post.title}
+ {post.title}
By {post.author}
);
- });
+ }).reverse();
}
diff --git a/src/components/User.js b/src/components/User.js
index 33d5b8b..10f3d5f 100644
--- a/src/components/User.js
+++ b/src/components/User.js
@@ -1,6 +1,8 @@
import React from 'react';
+import ReactMarkdown from 'react-markdown';
import { connect } from 'react-redux';
import { fetchUserProfile } from '../actions';
+import { Link } from 'react-router-dom';
class User extends React.Component {
constructor (props) {
@@ -14,6 +16,22 @@ class User extends React.Component {
this.props.fetchUserProfile(user)
.then(() => this.setState({isLoading: false}))
}
+ renderList() {
+ const posts = this.props.user.currentUser.posts
+ return posts.map(post => {
+ return (
+
+
+
+
{post.title}
+ By {post.author}
+
+
+
+
+ );
+ });
+ }
render () {
const {user} = this.props
@@ -24,13 +42,16 @@ class User extends React.Component {
} else {
const currentUser = user.currentUser
return (
-
-
+
+
-
{currentUser.username}
-
Email: {currentUser.email}
+
This is the page of: {currentUser.username}
+
Email: {currentUser.email}
Location: {currentUser.location}
About Me: {currentUser.bio}
+
+ {this.renderList()}
+
diff --git a/src/reducers/userReducer.js b/src/reducers/userReducer.js
index 153e729..0096219 100644
--- a/src/reducers/userReducer.js
+++ b/src/reducers/userReducer.js
@@ -1,10 +1,10 @@
const initialState = {
- currentUser: ""
+ currentUser: {}
};
export default (state = initialState, action) => {
switch (action.type) {
- case 'FETCH_USER_PROFILE':
+ case 'FETCH_USER':
return {currentUser: action.payload}
default:
return state;