AdminUsersSearchPageContainer.js 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. import { connect } from "react-redux";
  2. import { useEffect } from "react";
  3. import { useSearchParams } from "react-router-dom";
  4. import { actionUsersSearchPage } from "../../../../actions/actionUsersSearchPage";
  5. import { actionFeedUsersFind } from "../../../../reducers";
  6. import { InfScroll } from "../../../common/InfScroll";
  7. import { AdminUsersPage } from "../../AdminUsersPage";
  8. const AdminUsersSearchPageContainer = ({ feed, users, 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={users}
  21. component={AdminUsersPage}
  22. promiseStatus={promiseStatus}
  23. onScroll={() => onScroll({ feed, orderBy, text })}
  24. orderBy={orderBy}
  25. />
  26. );
  27. };
  28. export const CAdminUsersSearchPageContainer = connect(
  29. (state) => ({
  30. users: state.promise?.feedUsersFind?.payload || [],
  31. feed: state.feed?.payload || [],
  32. promiseStatus: state.promise?.feedUsersFind?.status || null,
  33. }),
  34. {
  35. onUnmount: () => ({ type: "USERS_SEARCH_PAGE_CLEAR" }),
  36. onLoad: ({ orderBy, text }) => actionUsersSearchPage({ orderBy, text }),
  37. onScroll: ({ feed, orderBy, text }) => actionFeedUsersFind({ text, skip: feed?.length || 0, orderBy }),
  38. }
  39. )(AdminUsersSearchPageContainer);