Working blog post!
This commit is contained in:
parent
09bc6c16fd
commit
04a64d3026
2 changed files with 28 additions and 2 deletions
|
@ -35,3 +35,14 @@ export const userLogin = (username, password) => async (dispatch) => {
|
||||||
export const loadCookieToState = (data) => async (dispatch) => {
|
export const loadCookieToState = (data) => async (dispatch) => {
|
||||||
dispatch({ type: 'LOAD_COOKIE', data })
|
dispatch({ type: 'LOAD_COOKIE', data })
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
export const newBlogPost = (payload) => async (dispatch) => {
|
||||||
|
const response = await sudoscientist.post('/blog', payload)
|
||||||
|
if (response.status === 401) {
|
||||||
|
dispatch({ type: 'BLOG_POST_FAILED', payload: null })
|
||||||
|
}
|
||||||
|
if (response.status === 200) {
|
||||||
|
dispatch({ type: 'BLOG_POST_CREATED', payload: response })
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
|
@ -1,22 +1,27 @@
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
|
import { useSelector } from "react-redux";
|
||||||
import ReactMde from "react-mde";
|
import ReactMde from "react-mde";
|
||||||
import ReactMarkdown from 'react-markdown';
|
import ReactMarkdown from 'react-markdown';
|
||||||
|
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"
|
||||||
|
import { newBlogPost } from '../actions';
|
||||||
|
|
||||||
const NewPost = (props) => {
|
const NewPost = (props) => {
|
||||||
const [title, setTitle] = React.useState("");
|
const [title, setTitle] = React.useState("");
|
||||||
const [content, setContent] = React.useState("");
|
const [content, setContent] = React.useState("");
|
||||||
const [tags, setTags] = React.useState("");
|
const [tags, setTags] = React.useState("");
|
||||||
const [selectedTab, setSelectedTab] = React.useState("write");
|
const [selectedTab, setSelectedTab] = React.useState("write");
|
||||||
|
const username = useSelector(state => state.auth.username);
|
||||||
|
|
||||||
const submitPost = () => {
|
const submitPost = () => {
|
||||||
const payload = {
|
const payload = {
|
||||||
title: title,
|
title: title,
|
||||||
content: content,
|
content: content,
|
||||||
tags: tags,
|
tags: tags,
|
||||||
|
author: username
|
||||||
}
|
}
|
||||||
console.log(payload)
|
props.newBlogPost(payload)
|
||||||
}
|
}
|
||||||
|
|
||||||
return(
|
return(
|
||||||
|
@ -49,4 +54,14 @@ const NewPost = (props) => {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
export default NewPost;
|
const mapStateToProps = (state) => {
|
||||||
|
return {
|
||||||
|
user: state.auth,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
export default connect(
|
||||||
|
mapStateToProps,
|
||||||
|
{ newBlogPost }
|
||||||
|
)(NewPost);
|
||||||
|
|
||||||
|
|
Reference in a new issue