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.

71 lines
2.1 KiB

  1. import React from 'react';
  2. import { connect } from 'react-redux';
  3. import { defineMessages, injectIntl } from 'react-intl';
  4. import ImmutablePureComponent from 'react-immutable-pure-component';
  5. import PropTypes from 'prop-types';
  6. import ImmutablePropTypes from 'react-immutable-proptypes';
  7. import LoadingIndicator from '../../components/loading_indicator';
  8. import { ScrollContainer } from 'react-router-scroll-4';
  9. import Column from '../ui/components/column';
  10. import ColumnBackButtonSlim from '../../components/column_back_button_slim';
  11. import AccountContainer from '../../containers/account_container';
  12. import { fetchMutes, expandMutes } from '../../actions/mutes';
  13. const messages = defineMessages({
  14. heading: { id: 'column.mutes', defaultMessage: 'Muted users' },
  15. });
  16. const mapStateToProps = state => ({
  17. accountIds: state.getIn(['user_lists', 'mutes', 'items']),
  18. });
  19. @connect(mapStateToProps)
  20. @injectIntl
  21. export default class Mutes extends ImmutablePureComponent {
  22. static propTypes = {
  23. params: PropTypes.object.isRequired,
  24. dispatch: PropTypes.func.isRequired,
  25. shouldUpdateScroll: PropTypes.func,
  26. accountIds: ImmutablePropTypes.list,
  27. intl: PropTypes.object.isRequired,
  28. };
  29. componentWillMount () {
  30. this.props.dispatch(fetchMutes());
  31. }
  32. handleScroll = (e) => {
  33. const { scrollTop, scrollHeight, clientHeight } = e.target;
  34. if (scrollTop === scrollHeight - clientHeight) {
  35. this.props.dispatch(expandMutes());
  36. }
  37. }
  38. render () {
  39. const { intl, shouldUpdateScroll, accountIds } = this.props;
  40. if (!accountIds) {
  41. return (
  42. <Column>
  43. <LoadingIndicator />
  44. </Column>
  45. );
  46. }
  47. return (
  48. <Column icon='volume-off' heading={intl.formatMessage(messages.heading)}>
  49. <ColumnBackButtonSlim />
  50. <ScrollContainer scrollKey='mutes' shouldUpdateScroll={shouldUpdateScroll}>
  51. <div className='scrollable mutes' onScroll={this.handleScroll}>
  52. {accountIds.map(id =>
  53. <AccountContainer key={id} id={id} />
  54. )}
  55. </div>
  56. </ScrollContainer>
  57. </Column>
  58. );
  59. }
  60. }