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) => { 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) { if (response.status === 201) {
window.location.reload() window.location.reload()
} }

View file

@ -1,7 +1,6 @@
import React from 'react'; import React from 'react';
import ReactMde from "react-mde"; import ReactMde from "react-mde";
import ReactMarkdown from 'react-markdown'; import ReactMarkdown from 'react-markdown';
import { useSelector } from "react-redux";
import { connect } from 'react-redux'; import { connect } from 'react-redux';
import 'github-markdown-css' import 'github-markdown-css'
import "react-mde/lib/styles/css/react-mde-all.css" import "react-mde/lib/styles/css/react-mde-all.css"
@ -10,12 +9,11 @@ import { newComment } from '../actions';
const Comment = (props) => { const Comment = (props) => {
const [content, setContent] = React.useState(""); const [content, setContent] = React.useState("");
const [selectedTab, setSelectedTab] = React.useState("write"); const [selectedTab, setSelectedTab] = React.useState("write");
const username = useSelector(state => state.auth.username);
const submitComment = () => { const submitComment = () => {
const payload = { const payload = {
content: content content: content
} }
props.newComment(username, payload) props.newComment(payload, props.post.currentId)
} }
return ( return (
<div> <div>
@ -32,12 +30,16 @@ const Comment = (props) => {
Promise.resolve(<ReactMarkdown source={markdown} />)} Promise.resolve(<ReactMarkdown source={markdown} />)}
/> />
</div> </div>
<div>
<button onClick={submitComment}>Submit Comment</button>
</div>
</div> </div>
) )
} }
const mapStateToProps = (state) => { const mapStateToProps = (state) => {
return { 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 { fetchPost,newComment } from '../actions';
import { Link } from 'react-router-dom'; import { Link } from 'react-router-dom';
import Comment from './Comments'; import Comment from './Comments';
import { useSelector } from "react-redux";
class Post extends React.Component { class Post extends React.Component {
constructor (props) { constructor (props) {
@ -13,8 +12,8 @@ class Post extends React.Component {
this.state = { this.state = {
isLoading: true isLoading: true
} }
console.log(props)
} }
componentDidMount() { componentDidMount() {
const { slug } = this.props.match.params const { slug } = this.props.match.params
this.props.fetchPost(slug) this.props.fetchPost(slug)