The code powering m.abunchtell.com https://m.abunchtell.com
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

58 lines
1.9 KiB

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