1
0
Fork 0

Working blog post!

This commit is contained in:
Amarpreet Minhas 2019-10-19 23:13:17 -04:00
parent 09bc6c16fd
commit 04a64d3026
2 changed files with 28 additions and 2 deletions

View file

@ -35,3 +35,14 @@ export const userLogin = (username, password) => async (dispatch) => {
export const loadCookieToState = (data) => async (dispatch) => {
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 })
}
};

View file

@ -1,22 +1,27 @@
import React from 'react';
import { useSelector } from "react-redux";
import ReactMde from "react-mde";
import ReactMarkdown from 'react-markdown';
import { connect } from 'react-redux';
import 'github-markdown-css'
import "react-mde/lib/styles/css/react-mde-all.css"
import { newBlogPost } from '../actions';
const NewPost = (props) => {
const [title, setTitle] = React.useState("");
const [content, setContent] = React.useState("");
const [tags, setTags] = React.useState("");
const [selectedTab, setSelectedTab] = React.useState("write");
const username = useSelector(state => state.auth.username);
const submitPost = () => {
const payload = {
title: title,
content: content,
tags: tags,
author: username
}
console.log(payload)
props.newBlogPost(payload)
}
return(
@ -49,4 +54,14 @@ const NewPost = (props) => {
)
}
export default NewPost;
const mapStateToProps = (state) => {
return {
user: state.auth,
};
}
export default connect(
mapStateToProps,
{ newBlogPost }
)(NewPost);