profileUserReducer.js 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. export const profileUserReducer = (
  2. state = {},
  3. { type, aboutUser, allPosts, newPosts, countPosts },
  4. ) => {
  5. const types = {
  6. 'PROFILE-PAGE-USER': () => {
  7. return {
  8. ...state,
  9. aboutUser,
  10. allPosts,
  11. }
  12. },
  13. 'CLEAR-DATA': () => {
  14. return {
  15. aboutUser: {},
  16. allPosts: [],
  17. }
  18. },
  19. 'CHANGE-AVATAR-USER': () => {
  20. return {
  21. ...state,
  22. aboutUser,
  23. }
  24. },
  25. 'COUNT_ALL_POSTS': () => {
  26. return {
  27. ...state,
  28. countPosts
  29. }
  30. }
  31. }
  32. if (type in types) {
  33. return types[type]()
  34. }
  35. return state
  36. }
  37. export const actionAvatarUpdate = (aboutUser) => ({
  38. type: 'CHANGE-AVATAR-USER',
  39. aboutUser,
  40. })
  41. export const actionProfilePageDataTypeUser = (aboutUser, allPosts) => ({
  42. type: 'PROFILE-PAGE-USER',
  43. aboutUser,
  44. allPosts,
  45. })
  46. export const actionCountPostsType = (countPosts) =>
  47. ({ type: "COUNT_ALL_POSTS", countPosts })
  48. export const actionProfilePageData = (id) =>
  49. ({ type: 'DATA_PROFILE', id })
  50. export const actionClearDataUserType = () =>
  51. ({ type: 'CLEAR-DATA' })