Skip to content

Instantly share code, notes, and snippets.

@aminbenselim
Created March 26, 2017 20:25
Show Gist options
  • Save aminbenselim/b136d89329815b5905f1ee02eb6bb69f to your computer and use it in GitHub Desktop.
Save aminbenselim/b136d89329815b5905f1ee02eb6bb69f to your computer and use it in GitHub Desktop.
action creators for the different action types
import axios from 'axios';
import {
GET_POSTS,
GET_POSTS_SUCCESS,
GET_POSTS_FAILURE,
GET_POST,
GET_POST_SUCCESS,
GET_POST_FAILURE,
} from './actions';
// Posts List action creators
export function getPosts(page) {
const request = axios({
method: 'get',
url: `/wp-json/wp/v2/posts?context=embed&per_page=4&page=${page}`,
headers: []
});
return {
type: GET_POSTS,
payload: request
};
}
export function getPostsSuccess(posts,totalpages,previous) {
return {
type: GET_POSTS_SUCCESS,
payload: posts,
totalpages,
posts: previous
};
}
export function getPostsFailure(error) {
return {
type: GET_POSTS_FAILURE,
payload: error
};
}
// Single Post action creators
export function getPost(id) {
const request = axios.get(`/wp-json/wp/v2/posts/${id}`);
return {
type: GET_POST,
payload: request
};
}
export function getPostSuccess(currentPost) {
return {
type: GET_POST_SUCCESS,
payload: currentPost
};
}
export function getPostFailure(error) {
return {
type: GET_POST_FAILURE,
payload: error
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment