userProfileReducer.js 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. export const userProfileReducer = (
  2. state = {},
  3. { type, aboutUser, allPosts, newPosts,newResult, countPosts },
  4. ) => {
  5. const types = {
  6. 'PROFILE-PAGE-USER': () => {
  7. return {
  8. ...state,
  9. aboutUser,
  10. // allPosts,
  11. }
  12. },
  13. 'USER-POSTS': () => {
  14. return {
  15. ...state,
  16. allPosts,
  17. // allPosts,
  18. }
  19. },
  20. 'CLEAR-DATA': () => {
  21. return {
  22. aboutUser: {},
  23. allPosts: [],
  24. }
  25. },
  26. 'CHANGE-AVATAR-USER': () => {
  27. return {
  28. ...state,
  29. aboutUser,
  30. }
  31. },
  32. 'COUNT_ALL_POSTS': () => {
  33. return {
  34. ...state,
  35. countPosts
  36. }
  37. },
  38. 'UPDATE_FOLLOWERS': () => {
  39. return {
  40. ...state,
  41. aboutUser: ({
  42. ...state.aboutUser,
  43. followers: [...newResult]
  44. })
  45. }
  46. }
  47. }
  48. if (type in types) {
  49. return types[type]()
  50. }
  51. return state
  52. }
  53. export const actionAvatarUpdate = (aboutUser) => ({
  54. type: 'CHANGE-AVATAR-USER',
  55. aboutUser,
  56. })
  57. export const actionProfilePageDataTypeUser = (aboutUser) => ({
  58. type: 'PROFILE-PAGE-USER',
  59. aboutUser})
  60. export const actionCountPostsType = (countPosts) =>
  61. ({ type: "COUNT_ALL_POSTS", countPosts })
  62. export const actionProfilePageData = (id) =>
  63. ({ type: 'DATA_PROFILE', id })
  64. export const actionUserAllPostsType = (allPosts) =>
  65. ({ type: 'USER-POSTS', allPosts })
  66. export const actionClearDataUserType = () =>
  67. ({ type: 'CLEAR-DATA' })
  68. export const actionChangeFollowersType = (newResult) => ({
  69. type:"UPDATE_FOLLOWERS", newResult
  70. })