actionCreators.js 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. import axios from 'axios';
  2. import * as constants from './constants';
  3. import {fromJS} from 'immutable';
  4. const setFeature = (data) => ({
  5. type: constants.GET_FEATURE,
  6. data: fromJS(data),
  7. });
  8. export const getFeature = () => {
  9. return (dispatch) => {
  10. axios.get('/posts/weight/v1/list', {
  11. params: {
  12. page: 1,
  13. size: 3
  14. }
  15. }).then(function (res) {
  16. if (res.success === 1) {
  17. dispatch(setFeature(res.models));
  18. }
  19. });
  20. }
  21. };
  22. const setBlogList = (data, nextPage, override) => ({
  23. type: constants.GET_BLOGLIST,
  24. data: fromJS(data),
  25. nextPage,
  26. override
  27. });
  28. const setfinished = () => ({
  29. type: constants.SET_FINISHED,
  30. });
  31. export const getBlogList = (page, override) => {
  32. return (dispatch) => {
  33. dispatch({type: constants.LOADING_TRUE});
  34. axios.get('/posts/posts/v1/list', {
  35. params: {
  36. page: page,
  37. size: 10
  38. }
  39. }).then(function (res) {
  40. if (res.success === 1) {
  41. let current = res.pageInfo.page * res.pageInfo.size;
  42. let total = res.pageInfo.total;
  43. dispatch(setBlogList(res.models, page + 1, override));
  44. if (current > total) dispatch(setfinished());
  45. }
  46. });
  47. }
  48. };
  49. export const getSocialList = () => {
  50. return (dispatch) => {
  51. axios.get('/social/social/v1/socials').then((res) => {
  52. if (res.success === 1) {
  53. dispatch({
  54. type: constants.GET_SOCIAL_LIST,
  55. data: fromJS(res.models)
  56. });
  57. }
  58. })
  59. }
  60. };