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.

82 lines
2.5 KiB

  1. import { connect } from 'react-redux';
  2. import PureRenderMixin from 'react-addons-pure-render-mixin';
  3. import ImmutablePropTypes from 'react-immutable-proptypes';
  4. import Column from '../ui/components/column';
  5. import { expandNotifications } from '../../actions/notifications';
  6. import NotificationContainer from './containers/notification_container';
  7. import { ScrollContainer } from 'react-router-scroll';
  8. import { defineMessages, injectIntl } from 'react-intl';
  9. import ColumnSettingsContainer from './containers/column_settings_container';
  10. import { createSelector } from 'reselect';
  11. import Immutable from 'immutable';
  12. const messages = defineMessages({
  13. title: { id: 'column.notifications', defaultMessage: 'Notifications' }
  14. });
  15. const getNotifications = createSelector([
  16. state => Immutable.List(state.getIn(['settings', 'notifications', 'shows']).filter(item => !item).keys()),
  17. state => state.getIn(['notifications', 'items'])
  18. ], (excludedTypes, notifications) => notifications.filterNot(item => excludedTypes.includes(item.get('type'))));
  19. const mapStateToProps = state => ({
  20. notifications: getNotifications(state)
  21. });
  22. const Notifications = React.createClass({
  23. propTypes: {
  24. notifications: ImmutablePropTypes.list.isRequired,
  25. dispatch: React.PropTypes.func.isRequired,
  26. trackScroll: React.PropTypes.bool,
  27. intl: React.PropTypes.object.isRequired
  28. },
  29. getDefaultProps () {
  30. return {
  31. trackScroll: true
  32. };
  33. },
  34. mixins: [PureRenderMixin],
  35. handleScroll (e) {
  36. const { scrollTop, scrollHeight, clientHeight } = e.target;
  37. if (scrollTop === scrollHeight - clientHeight) {
  38. this.props.dispatch(expandNotifications());
  39. }
  40. },
  41. render () {
  42. const { intl, notifications, trackScroll } = this.props;
  43. const scrollableArea = (
  44. <div className='scrollable' onScroll={this.handleScroll}>
  45. <div>
  46. {notifications.map(item => <NotificationContainer key={item.get('id')} notification={item} accountId={item.get('account')} />)}
  47. </div>
  48. </div>
  49. );
  50. if (trackScroll) {
  51. return (
  52. <Column icon='bell' heading={intl.formatMessage(messages.title)}>
  53. <ScrollContainer scrollKey='notifications'>
  54. {scrollableArea}
  55. </ScrollContainer>
  56. </Column>
  57. );
  58. } else {
  59. return (
  60. <Column icon='bell' heading={intl.formatMessage(messages.title)}>
  61. <ColumnSettingsContainer />
  62. {scrollableArea}
  63. </Column>
  64. );
  65. }
  66. }
  67. });
  68. export default connect(mapStateToProps)(injectIntl(Notifications));