feedReducer.js 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. import { actionCatAll } from "../actions/actionCatAll";
  2. import { actionGoodsFind } from "../actions/actionGoodsFind";
  3. import { actionCatsFind } from "../actions/actionCatsFind";
  4. import { actionGoodsAll } from "../actions/actionGoodsAll";
  5. import { actionOrdersAll } from "../actions/actionOrdersAll";
  6. import { actionOrdersFind } from "../actions/actionOrdersFind";
  7. import { actionCategoryGoods } from "../actions/actionCategoryGoods";
  8. import { actionUsersFind } from "../actions/actionUsersFind";
  9. import { actionUsersAll } from "../actions/actionUsersAll";
  10. function feedReducer(state = { payload: [] }, { type, payload = [] }) {
  11. if (type === "FEED_ADD") {
  12. return {
  13. ...state,
  14. payload: [...new Map([...state["payload"], ...payload].map((item) => [item["_id"], item])).values()],
  15. };
  16. }
  17. if (type === "FEED_CLEAR") {
  18. return { payload: [] };
  19. }
  20. return state || { payload: [] };
  21. }
  22. const actionFeedAdd = (payload) => ({ type: "FEED_ADD", payload });
  23. const actionFeedClear = () => ({ type: "FEED_CLEAR" });
  24. const actionFeedGoods = ({ skip = 0, orderBy = "_id" }) => actionGoodsAll({ skip, limit: 10, promiseName: "feedGoodsAll", orderBy });
  25. const actionFeedCategoryGoods = ({ skip = 0, orderBy = "_id", category }) =>
  26. actionCategoryGoods({ skip, limit: 8, promiseName: "feedCategoryGoods", orderBy, category });
  27. const actionFeedGoodsFind = ({ skip = 0, text = "", orderBy = "_id" }) =>
  28. actionGoodsFind({ skip, limit: 10, promiseName: "feedGoodsFind", text, orderBy });
  29. const actionFeedCatsFind = ({ skip = 0, text = "", orderBy = "_id" }) =>
  30. actionCatsFind({ skip, promiseName: "feedCatsFind", text, limit: 10, orderBy });
  31. const actionFeedCats = ({ skip = 0, orderBy = "_id" }) => actionCatAll({ promiseName: "feedCatAll", skip, limit: 10, orderBy });
  32. const actionFeedOrders = ({ skip = 0, orderBy = "_id", status = 0 }) =>
  33. actionOrdersAll({ skip, limit: 10, promiseName: "feedOrdersAll", orderBy, status });
  34. const actionFeedOrdersFind = ({ skip = 0, text = "", orderBy = "_id", status = "0" }) =>
  35. actionOrdersFind({ skip, limit: 10, promiseName: "feedOrdersFind", text, orderBy, status });
  36. const actionFeedUsersFind = ({ skip = 0, text = "", orderBy = "_id" }) =>
  37. actionUsersFind({ skip, promiseName: "feedUsersFind", text, limit: 10, orderBy });
  38. const actionFeedUsers = ({ skip = 0, orderBy = "_id" }) => actionUsersAll({ promiseName: "feedUsersAll", skip, limit: 10, orderBy });
  39. export {
  40. actionFeedCats,
  41. actionFeedCatsFind,
  42. actionFeedGoods,
  43. actionFeedClear,
  44. actionFeedAdd,
  45. actionFeedGoodsFind,
  46. feedReducer,
  47. actionFeedOrders,
  48. actionFeedOrdersFind,
  49. actionFeedCategoryGoods,
  50. actionFeedUsers,
  51. actionFeedUsersFind,
  52. };