activities.js 754 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. import { queryActivities } from '../services/api';
  2. export default {
  3. namespace: 'activities',
  4. state: {
  5. list: [],
  6. loading: true,
  7. },
  8. effects: {
  9. *fetchList(_, { call, put }) {
  10. yield put({
  11. type: 'changeLoading',
  12. payload: true,
  13. });
  14. const response = yield call(queryActivities);
  15. yield put({
  16. type: 'saveList',
  17. payload: response,
  18. });
  19. yield put({
  20. type: 'changeLoading',
  21. payload: false,
  22. });
  23. },
  24. },
  25. reducers: {
  26. saveList(state, action) {
  27. return {
  28. ...state,
  29. list: action.payload,
  30. };
  31. },
  32. changeLoading(state, action) {
  33. return {
  34. ...state,
  35. loading: action.payload,
  36. };
  37. },
  38. },
  39. };