Skip to content

Commit

Permalink
receive new post
Browse files Browse the repository at this point in the history
  • Loading branch information
StephenGrider committed Apr 20, 2017
1 parent d7b6b24 commit 7b89b3b
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
10 changes: 10 additions & 0 deletions blog/src/actions/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import axios from 'axios';

export const FETCH_POSTS = 'fetch_posts';
export const FETCH_POST = 'fetch_post';
export const CREATE_POST = 'create_post';

const ROOT_URL = 'http://reduxblog.herokuapp.com/api';
Expand All @@ -24,3 +25,12 @@ export function createPost(values, callback) {
payload: request
};
}

export function fetchPost(id) {
const request = axios.get(`${ROOT_URL}/posts/${id}${API_KEY}`);

return {
type: FETCH_POST,
payload: request
};
}
9 changes: 8 additions & 1 deletion blog/src/reducers/reducer_posts.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
import _ from 'lodash';
import { FETCH_POSTS } from '../actions';
import { FETCH_POSTS, FETCH_POST } from '../actions';

export default function(state = {}, action) {
switch (action.type) {
case FETCH_POST:
// const post = action.payload.data;
// const newState = { ...state };
// newState[post.id] = post;
// return newState;

return { ...state, [action.payload.data.id]: action.payload.data };
case FETCH_POSTS:
return _.mapKeys(action.payload.data, 'id');
default:
Expand Down

0 comments on commit 7b89b3b

Please sign in to comment.