1
0
Fork 0

Breakpoint for breaking changes

This commit is contained in:
Amarpreet Minhas 2020-01-29 21:23:23 -05:00
parent 221787eba4
commit 9c3037fb7e
2 changed files with 72 additions and 66 deletions

View file

@ -64,3 +64,10 @@ export const newBlogPost = (payload) => async (dispatch) => {
history.push('/posts/' + response.data.slug)
}
};
export const newComment = (payload, parent_id) => async (dispatch) => {
const response = await sudoscientist.post('/blog/comments' + parent_id, payload)
if (response.status === 201) {
window.location.reload()
}
};

View file

@ -2,7 +2,7 @@ import React from 'react';
import ReactMarkdown from 'react-markdown';
import 'github-markdown-css'
import { connect } from 'react-redux';
import { fetchPost } from '../actions';
import { fetchPost,newComment } from '../actions';
import { Link } from 'react-router-dom';
class Post extends React.Component {
@ -18,7 +18,7 @@ class Post extends React.Component {
.then(() => this.setState({isLoading: false}))
}
renderComments(comments) {
renderComments(comments, parent_id) {
if (comments) {
return comments.map(comment => {
return (
@ -51,14 +51,13 @@ class Post extends React.Component {
</div>
</div>
</div>
{ this.renderComments(post.comments) }
{ this.renderComments(post.comments,post.id) }
</div>
)
}
render () {
const {isLoading} = this.state
if (isLoading) {
return <p>Loading</p>
} else {
@ -80,5 +79,5 @@ const mapStateToProps = (state) => {
export default connect(
mapStateToProps,
{ fetchPost }
{ fetchPost, newComment },
)(Post);