exploreReducer.js 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. export const exploreReducer = (
  2. state = {},
  3. { skip, type, newPosts = [],explorePostsCount, postId, explorePosts, postsFeedCount,newPostsExploreCount, newResult },
  4. ) => {
  5. const types = {
  6. 'ADD-EXPLORE-POSTS': () => {
  7. return {
  8. ...state,
  9. explorePosts: state?.explorePosts ? [...state.explorePosts, ...newPosts] : [...newPosts],
  10. explorePostsCount: explorePostsCount ? explorePostsCount : newPostsExploreCount
  11. }
  12. },
  13. 'EXPLORE-COUNT': () => {
  14. return {
  15. ...state,
  16. explorePostsCount: explorePostsCount ? explorePostsCount : newPostsExploreCount,
  17. }
  18. },
  19. 'EXPLORE-POSTS': () => {
  20. return {
  21. ...state,
  22. explorePosts: explorePosts ,
  23. }
  24. },
  25. 'CLEAR_EXPLORE_POSTS': () => ({
  26. ...state,
  27. explorePosts: [],
  28. explorePostsCount: 0,
  29. }),
  30. }
  31. if (type in types) {
  32. return types[type]()
  33. }
  34. return state
  35. }
  36. // export const actionAllClearExplore = () => async (dispatch) => {
  37. // Promise.all([
  38. // await dispatch(actionClearPromiseForName('explorePosts')),
  39. // await dispatch(actionClearPromiseForName('explorePostsCount')),
  40. // await dispatch(actionClearExplorePosts())
  41. // ])
  42. // }
  43. export const actionClearExplorePosts = () =>
  44. ({ type: 'CLEAR_EXPLORE_POSTS' })
  45. export const actionExploreType = (newPosts,newPostsExploreCount) =>
  46. ({ type: 'ADD-EXPLORE-POSTS', newPosts, newPostsExploreCount })
  47. export const actionExploreTypeCount = (explorePostsCount) =>
  48. ({ type: 'EXPLORE-COUNT', explorePostsCount })