diff --git a/src/actions/index.js b/src/actions/index.js
index 21d7ba3..56164d0 100644
--- a/src/actions/index.js
+++ b/src/actions/index.js
@@ -9,7 +9,7 @@ export const fetchPosts = () => async (dispatch) => {
export const fetchPost = (slug) => async (dispatch) => {
const post = await sudoscientist.get('/blog/posts/by-slug/' + slug)
const comments = await sudoscientist.get('/blog/comments/' + post.data.id);
- const response = { ...post.data, ...comments.data }
+ const response = { post: post.data, comments: comments.data }
dispatch({ type: 'FETCH_POST', payload: response })
};
diff --git a/src/components/Post.js b/src/components/Post.js
index 350fd85..45abaed 100644
--- a/src/components/Post.js
+++ b/src/components/Post.js
@@ -18,27 +18,55 @@ class Post extends React.Component {
.then(() => this.setState({isLoading: false}))
}
- render () {
+ renderComments() {
+ //if (comments.length) {
+ //return comments.map(comment => {
+ // return (
+ //
+ // );
+ //});
+ //}
+ }
+
+ renderPost() {
const {posts} = this.props
+ const post = posts.entities[posts.currentId]
+ console.log(post)
+ return(
+
+
+
+
+
{post.title}
+
By {post.author}
+
Posted {post.time_published}
+
+
+
+
+
+
+ { this.renderComments(post.comments) }
+
+ )
+ }
+
+ render () {
const {isLoading} = this.state
if (isLoading) {
return Loading
} else {
- const post = posts.entities[posts.currentId]
return (
-
-
-
-
{post.title}
-
By {post.author}
-
Posted {post.time_published}
-
-
-
-
-
-
+
+ { this.renderPost() }
+
);
}
}
@@ -47,8 +75,7 @@ class Post extends React.Component {
const mapStateToProps = (state) => {
return {
posts: state.posts,
- slug: state.slug,
- comments: state.comments
+ slug: state.slug
};
}
diff --git a/src/reducers/postsReducer.js b/src/reducers/postsReducer.js
index 87faf24..e9feb70 100644
--- a/src/reducers/postsReducer.js
+++ b/src/reducers/postsReducer.js
@@ -17,8 +17,8 @@ export default (state = initialState, action) => {
return {...state, ...{entities: mergedEntities}}
case 'FETCH_POST':
- mergedEntities = normalizeEntities(state.entities, [action.payload])
- return {...state, ...{entities: mergedEntities, currentId: action.payload.id}}
+ mergedEntities = normalizeEntities(state.entities, [action.payload.post])
+ return {...state, ...{entities: mergedEntities, currentId: action.payload.post.id}}
default:
return state;
}