1
0
Fork 0

Compare commits

...

1 commit

Author SHA1 Message Date
9c3037fb7e Breakpoint for breaking changes 2020-01-29 21:23:23 -05:00
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) 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 ReactMarkdown from 'react-markdown';
import 'github-markdown-css' import 'github-markdown-css'
import { connect } from 'react-redux'; import { connect } from 'react-redux';
import { fetchPost } from '../actions'; import { fetchPost,newComment } from '../actions';
import { Link } from 'react-router-dom'; import { Link } from 'react-router-dom';
class Post extends React.Component { class Post extends React.Component {
@ -18,7 +18,7 @@ class Post extends React.Component {
.then(() => this.setState({isLoading: false})) .then(() => this.setState({isLoading: false}))
} }
renderComments(comments) { renderComments(comments, parent_id) {
if (comments) { if (comments) {
return comments.map(comment => { return comments.map(comment => {
return ( return (
@ -51,14 +51,13 @@ class Post extends React.Component {
</div> </div>
</div> </div>
</div> </div>
{ this.renderComments(post.comments) } { this.renderComments(post.comments,post.id) }
</div> </div>
) )
} }
render () { render () {
const {isLoading} = this.state const {isLoading} = this.state
if (isLoading) { if (isLoading) {
return <p>Loading</p> return <p>Loading</p>
} else { } else {
@ -80,5 +79,5 @@ const mapStateToProps = (state) => {
export default connect( export default connect(
mapStateToProps, mapStateToProps,
{ fetchPost } { fetchPost, newComment },
)(Post); )(Post);