1
0
Fork 0

Fix up path to blog posts

This commit is contained in:
Amarpreet Minhas 2020-01-25 23:40:48 -05:00
parent 58a8fa234a
commit 38bd1ebfd6
2 changed files with 7 additions and 5 deletions

View file

@ -2,18 +2,19 @@ import sudoscientist from '../apis/sudoscientist';
import history from './history'
export const fetchPosts = () => async (dispatch) => {
const response = await sudoscientist.get('/blog');
const response = await sudoscientist.get('/blog/posts');
dispatch({ type: 'FETCH_POSTS', payload: response.data })
};
export const fetchPost = (slug) => async (dispatch) => {
const response = await sudoscientist.get('/blog/by-slug/' + slug);
const response = await sudoscientist.get('/blog/posts/by-slug/' + slug);
dispatch({ type: 'FETCH_POST', payload: response.data })
};
export const fetchUserProfile = (user) => async (dispatch) => {
const profile = await sudoscientist.get('/users/' + user);
const userPosts = await sudoscientist.get('/blog/by-author/' + user);
const userPosts = await sudoscientist.get('/blog/posts/by-author/' + user);
const test = {posts: userPosts.data}
const response = { ...profile.data, ...test }
dispatch({ type: 'FETCH_USER', payload: response })
@ -55,7 +56,7 @@ export const loadCookieToState = (data) => async (dispatch) => {
export const newBlogPost = (payload) => async (dispatch) => {
const response = await sudoscientist.post('/blog', payload)
const response = await sudoscientist.post('/blog/posts', payload)
if (response.status === 201) {
history.push('/posts/' + response.data.slug)
}

View file

@ -47,7 +47,8 @@ class Post extends React.Component {
const mapStateToProps = (state) => {
return {
posts: state.posts,
slug: state.slug
slug: state.slug,
comments: state.comments
};
}