1
0
Fork 0

I think I get it, again!

This commit is contained in:
Amarpreet Minhas 2020-01-30 00:37:37 -05:00
parent 8123b0d65f
commit e1dee7fe14
3 changed files with 8 additions and 7 deletions

View file

@ -66,7 +66,7 @@ export const newBlogPost = (payload) => async (dispatch) => {
};
export const newComment = (payload, parent_id) => async (dispatch) => {
const response = await sudoscientist.post('/blog/comments' + parent_id, payload)
const response = await sudoscientist.post('/blog/comments/' + parent_id, payload)
if (response.status === 201) {
window.location.reload()
}

View file

@ -1,7 +1,6 @@
import React from 'react';
import ReactMde from "react-mde";
import ReactMarkdown from 'react-markdown';
import { useSelector } from "react-redux";
import { connect } from 'react-redux';
import 'github-markdown-css'
import "react-mde/lib/styles/css/react-mde-all.css"
@ -10,12 +9,11 @@ import { newComment } from '../actions';
const Comment = (props) => {
const [content, setContent] = React.useState("");
const [selectedTab, setSelectedTab] = React.useState("write");
const username = useSelector(state => state.auth.username);
const submitComment = () => {
const payload = {
content: content
}
props.newComment(username, payload)
props.newComment(payload, props.post.currentId)
}
return (
<div>
@ -32,12 +30,16 @@ const Comment = (props) => {
Promise.resolve(<ReactMarkdown source={markdown} />)}
/>
</div>
<div>
<button onClick={submitComment}>Submit Comment</button>
</div>
</div>
)
}
const mapStateToProps = (state) => {
return {
user: state.auth
post: state.posts,
user: state.auth,
};
}

View file

@ -5,7 +5,6 @@ import { connect } from 'react-redux';
import { fetchPost,newComment } from '../actions';
import { Link } from 'react-router-dom';
import Comment from './Comments';
import { useSelector } from "react-redux";
class Post extends React.Component {
constructor (props) {
@ -13,8 +12,8 @@ class Post extends React.Component {
this.state = {
isLoading: true
}
console.log(props)
}
componentDidMount() {
const { slug } = this.props.match.params
this.props.fetchPost(slug)