AdminGoodsPageContainer.js 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. import { actionGoodsPage } from "../../../../actions/actionGoodsPage";
  2. import { useSearchParams } from "react-router-dom";
  3. import { useEffect } from "react";
  4. import { InfScroll } from "../../../common/InfScroll";
  5. import { AdminGoodsPage } from "../../AdminGoodsPage";
  6. import { connect } from "react-redux";
  7. import { actionFeedGoods } from "../../../../reducers";
  8. const AdminGoodsPageContainer = ({ feed, goods, promiseStatus, onLoad, onUnmount, onScroll }) => {
  9. const [searchParams] = useSearchParams();
  10. const orderBy = searchParams.get("orderBy") || "_id";
  11. useEffect(() => {
  12. onLoad({ orderBy });
  13. return () => {
  14. onUnmount();
  15. };
  16. }, [orderBy]);
  17. return (
  18. <InfScroll
  19. items={goods}
  20. component={AdminGoodsPage}
  21. promiseStatus={promiseStatus}
  22. onScroll={() => onScroll({ feed, orderBy })}
  23. orderBy={orderBy}
  24. />
  25. );
  26. };
  27. export const CAdminGoodsPageContainer = connect(
  28. (state) => ({
  29. goods: state.promise?.feedGoodsAll?.payload || [],
  30. feed: state.feed?.payload || [],
  31. promiseStatus: state.promise?.feedGoodsAll?.status || null,
  32. }),
  33. {
  34. onUnmount: () => ({ type: "GOODS_PAGE_CLEAR" }),
  35. onLoad: ({ orderBy }) => actionGoodsPage({ orderBy }),
  36. onScroll: ({ feed, orderBy }) => actionFeedGoods({ skip: feed?.length || 0, orderBy }),
  37. }
  38. )(AdminGoodsPageContainer);