GoodsSearchPageContainer.js 1.5 KB

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