Set up basic comment stuff
This commit is contained in:
parent
180a0a0cfb
commit
8123b0d65f
2 changed files with 52 additions and 1 deletions
47
src/components/Comments.js
Normal file
47
src/components/Comments.js
Normal file
|
@ -0,0 +1,47 @@
|
||||||
|
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"
|
||||||
|
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)
|
||||||
|
}
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
<div className="comment">
|
||||||
|
<h3><b>Leave a comment!</b></h3>
|
||||||
|
</div>
|
||||||
|
<div className="markdown-body">
|
||||||
|
<ReactMde
|
||||||
|
value={content}
|
||||||
|
onChange={setContent}
|
||||||
|
selectedTab={selectedTab}
|
||||||
|
onTabChange={setSelectedTab}
|
||||||
|
generateMarkdownPreview={(markdown) =>
|
||||||
|
Promise.resolve(<ReactMarkdown source={markdown} />)}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
const mapStateToProps = (state) => {
|
||||||
|
return {
|
||||||
|
user: state.auth
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
export default connect(
|
||||||
|
mapStateToProps,
|
||||||
|
{ newComment },
|
||||||
|
)(Comment);
|
|
@ -4,6 +4,8 @@ import 'github-markdown-css'
|
||||||
import { connect } from 'react-redux';
|
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 { useSelector } from "react-redux";
|
||||||
|
|
||||||
class Post extends React.Component {
|
class Post extends React.Component {
|
||||||
constructor (props) {
|
constructor (props) {
|
||||||
|
@ -11,11 +13,12 @@ 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)
|
||||||
.then(() => this.setState({isLoading: false}))
|
.then(() => this.setState({isLoading: false, slug: slug}))
|
||||||
}
|
}
|
||||||
|
|
||||||
renderComments(comments, parent_id) {
|
renderComments(comments, parent_id) {
|
||||||
|
@ -50,6 +53,7 @@ class Post extends React.Component {
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<Comment></Comment>
|
||||||
</div>
|
</div>
|
||||||
{ this.renderComments(post.comments,post.id) }
|
{ this.renderComments(post.comments,post.id) }
|
||||||
</div>
|
</div>
|
||||||
|
|
Reference in a new issue