status_list_container.js 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. import { createSelector } from '@reduxjs/toolkit';
  2. import { Map as ImmutableMap, List as ImmutableList } from 'immutable';
  3. import { connect } from 'react-redux';
  4. import { debounce } from 'lodash';
  5. import { scrollTopTimeline, loadPending } from '../../../actions/timelines';
  6. import StatusList from '../../../components/status_list';
  7. import { me } from '../../../initial_state';
  8. const makeGetStatusIds = (pending = false) => createSelector([
  9. (state, { type }) => state.getIn(['settings', type], ImmutableMap()),
  10. (state, { type }) => state.getIn(['timelines', type, pending ? 'pendingItems' : 'items'], ImmutableList()),
  11. (state) => state.get('statuses'),
  12. ], (columnSettings, statusIds, statuses) => {
  13. return statusIds.filter(id => {
  14. if (id === null || id === 'inline-follow-suggestions') return true;
  15. const statusForId = statuses.get(id);
  16. let showStatus = true;
  17. if (statusForId.get('account') === me) return true;
  18. if (columnSettings.getIn(['shows', 'reblog']) === false) {
  19. showStatus = showStatus && statusForId.get('reblog') === null;
  20. }
  21. if (columnSettings.getIn(['shows', 'reply']) === false) {
  22. showStatus = showStatus && (statusForId.get('in_reply_to_id') === null || statusForId.get('in_reply_to_account_id') === me);
  23. }
  24. return showStatus;
  25. });
  26. });
  27. const makeMapStateToProps = () => {
  28. const getStatusIds = makeGetStatusIds();
  29. const getPendingStatusIds = makeGetStatusIds(true);
  30. const mapStateToProps = (state, { timelineId }) => ({
  31. statusIds: getStatusIds(state, { type: timelineId }),
  32. lastId: state.getIn(['timelines', timelineId, 'items'])?.last(),
  33. isLoading: state.getIn(['timelines', timelineId, 'isLoading'], true),
  34. isPartial: state.getIn(['timelines', timelineId, 'isPartial'], false),
  35. hasMore: state.getIn(['timelines', timelineId, 'hasMore']),
  36. numPending: getPendingStatusIds(state, { type: timelineId }).size,
  37. });
  38. return mapStateToProps;
  39. };
  40. const mapDispatchToProps = (dispatch, { timelineId }) => ({
  41. onScrollToTop: debounce(() => {
  42. dispatch(scrollTopTimeline(timelineId, true));
  43. }, 100),
  44. onScroll: debounce(() => {
  45. dispatch(scrollTopTimeline(timelineId, false));
  46. }, 100),
  47. onLoadPending: () => dispatch(loadPending(timelineId)),
  48. });
  49. export default connect(makeMapStateToProps, mapDispatchToProps)(StatusList);