GoodsSearchPageContainer.js 1.6 KB

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