From 5f352030d4af5432aaac85b622490d4191507f6e Mon Sep 17 00:00:00 2001 From: Asara Date: Wed, 29 Jan 2020 21:22:46 -0500 Subject: [PATCH] Breakpoint for breaking changes --- src/actions/index.js | 7 ++ src/components/.NewPost.js.swp | Bin 0 -> 12288 bytes src/components/Post.js | 131 ++++++++++++++++----------------- 3 files changed, 72 insertions(+), 66 deletions(-) create mode 100644 src/components/.NewPost.js.swp diff --git a/src/actions/index.js b/src/actions/index.js index fe98b11..f0fa858 100644 --- a/src/actions/index.js +++ b/src/actions/index.js @@ -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() + } +}; diff --git a/src/components/.NewPost.js.swp b/src/components/.NewPost.js.swp new file mode 100644 index 0000000000000000000000000000000000000000..4744378e961c7c10279e9b743012b86c44eb0aec GIT binary patch literal 12288 zcmeI2L2ukd6vw9=fYP);5El^AU?j4OcI_4}DA`>^S4be#Dq;f{)WfVj*>!4rEYCRG zXuELXz(+t-d;kO&BtVD*oZ-R|^}-DV5{L^IZv1EL*>zTF8;+o{^o#A8H*eni&pazp zW_Zls?-+-HEF&Sq zm}e@Ms(T>2`-R99&!RvUVGxQm7a2NbaFx$?g;f55yqj0o=M-=XoKAuBJ3eg{8-kHHbhK?I%yPk~Kv0c?PC;1}e3 z8+;4C0$+kJz(?SHpuiMpUG{;yoB~b(r+`zyDc}@v3jA9I+O7IDV|#~CTyvW7+2uq` z^a)40Fl{NzM~W%FCw2>w%MRf;a#1K6@qJb%iiRS~c&J+V?aJ6MDp%TFDS5F?r5^3G zQcXL?px~-3GCC(1iCNbC(>`sP5pCKZz{q%Qn}NL`iVp|okW01)Qs-W722(fUYzBnIytvSTzW1n zLmEr&7hH$VZE%vKS5%Pi*2O<^al4b8+WQ!{aMLd^3IA*Ee< literal 0 HcmV?d00001 diff --git a/src/components/Post.js b/src/components/Post.js index 645a2c3..d7af679 100644 --- a/src/components/Post.js +++ b/src/components/Post.js @@ -2,83 +2,82 @@ 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 { - constructor (props) { - super(props) - this.state = { - isLoading: true - } - } - componentDidMount() { - const { slug } = this.props.match.params - this.props.fetchPost(slug) - .then(() => this.setState({isLoading: false})) + constructor (props) { + super(props) + this.state = { + isLoading: true } + } + componentDidMount() { + const { slug } = this.props.match.params + this.props.fetchPost(slug) + .then(() => this.setState({isLoading: false})) + } - renderComments(comments) { - if (comments) { - return comments.map(comment => { - return ( -
-
-
- -
-
-
- ); - }); - } - } - - renderPost() { - const {posts} = this.props - const post = posts.entities[posts.currentId] - return( -
-
-
-
-

{post.title}

-

By {post.author}

-

Posted {post.time_published}

-
- -
-
-
-
- { this.renderComments(post.comments) } -
- ) - } - - render () { - const {isLoading} = this.state - - if (isLoading) { - return

Loading

- } else { - return ( -
- { this.renderPost() } + renderComments(comments, parent_id) { + if (comments) { + return comments.map(comment => { + return ( +
+
+
+
- ); - } +
+
+ ); + }); } + } + + renderPost() { + const {posts} = this.props + const post = posts.entities[posts.currentId] + return( +
+
+
+
+

{post.title}

+

By {post.author}

+

Posted {post.time_published}

+
+ +
+
+
+
+ { this.renderComments(post.comments,post.id) } +
+ ) + } + + render () { + const {isLoading} = this.state + if (isLoading) { + return

Loading

+ } else { + return ( +
+ { this.renderPost() } +
+ ); + } + } } const mapStateToProps = (state) => { - return { - posts: state.posts, - slug: state.slug - }; + return { + posts: state.posts, + slug: state.slug + }; } export default connect( - mapStateToProps, - { fetchPost } + mapStateToProps, + { fetchPost, newComment }, )(Post);