AdminUsersSearchPageContainer.js 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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 { actionUsersSearchPageClear } from "../../../../actions/actionUsersSearchPageClear";
  6. import { actionFeedUsersFind } from "../../../../reducers";
  7. import { InfScroll } from "../../../common/InfScroll";
  8. import { AdminUsersPage } from "../../AdminUsersPage";
  9. const AdminUsersSearchPageContainer = ({ feed, users, 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={users}
  22. component={AdminUsersPage}
  23. promiseStatus={promiseStatus}
  24. onScroll={() => onScroll({ feed, orderBy, text })}
  25. orderBy={orderBy}
  26. />
  27. );
  28. };
  29. export const CAdminUsersSearchPageContainer = connect(
  30. (state) => ({
  31. users: state.promise?.feedUsersFind?.payload || [],
  32. feed: state.feed?.payload || [],
  33. promiseStatus: state.promise?.feedUsersFind?.status || null,
  34. }),
  35. {
  36. onUnmount: () => actionUsersSearchPageClear(),
  37. onLoad: ({ orderBy, text }) => actionUsersSearchPage({ orderBy, text }),
  38. onScroll: ({ feed, orderBy, text }) => actionFeedUsersFind({ text, skip: feed?.length || 0, orderBy }),
  39. }
  40. )(AdminUsersSearchPageContainer);