status_list_container.js 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. import { connect } from 'react-redux';
  2. import StatusList from '../../../components/status_list';
  3. import { expandTimeline, scrollTopTimeline } from '../../../actions/timelines';
  4. import Immutable from 'immutable';
  5. import { createSelector } from 'reselect';
  6. import { debounce } from 'react-decoration';
  7. const makeGetStatusIds = () => createSelector([
  8. (state, { type }) => state.getIn(['settings', type], Immutable.Map()),
  9. (state, { type }) => state.getIn(['timelines', type, 'items'], Immutable.List()),
  10. (state) => state.get('statuses'),
  11. (state) => state.getIn(['meta', 'me'])
  12. ], (columnSettings, statusIds, statuses, me) => statusIds.filter(id => {
  13. const statusForId = statuses.get(id);
  14. let showStatus = true;
  15. if (columnSettings.getIn(['shows', 'reblog']) === false) {
  16. showStatus = showStatus && statusForId.get('reblog') === null;
  17. }
  18. if (columnSettings.getIn(['shows', 'reply']) === false) {
  19. showStatus = showStatus && (statusForId.get('in_reply_to_id') === null || statusForId.get('in_reply_to_account_id') === me);
  20. }
  21. if (columnSettings.getIn(['regex', 'body'], '').trim().length > 0) {
  22. try {
  23. if (showStatus) {
  24. const regex = new RegExp(columnSettings.getIn(['regex', 'body']).trim(), 'i');
  25. showStatus = !regex.test(statusForId.get('reblog') ? statuses.getIn([statusForId.get('reblog'), 'search_index']) : statusForId.get('search_index'));
  26. }
  27. } catch(e) {
  28. // Bad regex, don't affect filters
  29. }
  30. }
  31. return showStatus;
  32. }));
  33. const makeMapStateToProps = () => {
  34. const getStatusIds = makeGetStatusIds();
  35. const mapStateToProps = (state, props) => ({
  36. scrollKey: props.scrollKey,
  37. shouldUpdateScroll: props.shouldUpdateScroll,
  38. statusIds: getStatusIds(state, props),
  39. isLoading: state.getIn(['timelines', props.type, 'isLoading'], true),
  40. isUnread: state.getIn(['timelines', props.type, 'unread']) > 0,
  41. hasMore: !!state.getIn(['timelines', props.type, 'next'])
  42. });
  43. return mapStateToProps;
  44. };
  45. const mapDispatchToProps = (dispatch, { type, id }) => ({
  46. @debounce(300, true)
  47. onScrollToBottom () {
  48. dispatch(scrollTopTimeline(type, false));
  49. dispatch(expandTimeline(type, id));
  50. },
  51. @debounce(100)
  52. onScrollToTop () {
  53. dispatch(scrollTopTimeline(type, true));
  54. },
  55. @debounce(100)
  56. onScroll () {
  57. dispatch(scrollTopTimeline(type, false));
  58. }
  59. });
  60. export default connect(makeMapStateToProps, mapDispatchToProps)(StatusList);