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.

78 lines
2.4 KiB

  1. import React from 'react';
  2. import { connect } from 'react-redux';
  3. import { defineMessages, injectIntl, FormattedMessage } 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 { debounce } from 'lodash';
  8. import LoadingIndicator from '../../components/loading_indicator';
  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. import ScrollableList from '../../components/scrollable_list';
  14. const messages = defineMessages({
  15. heading: { id: 'column.mutes', defaultMessage: 'Muted users' },
  16. });
  17. const mapStateToProps = state => ({
  18. accountIds: state.getIn(['user_lists', 'mutes', 'items']),
  19. hasMore: !!state.getIn(['user_lists', 'mutes', 'next']),
  20. });
  21. export default @connect(mapStateToProps)
  22. @injectIntl
  23. class Mutes extends ImmutablePureComponent {
  24. static propTypes = {
  25. params: PropTypes.object.isRequired,
  26. dispatch: PropTypes.func.isRequired,
  27. shouldUpdateScroll: PropTypes.func,
  28. hasMore: PropTypes.bool,
  29. accountIds: ImmutablePropTypes.list,
  30. intl: PropTypes.object.isRequired,
  31. multiColumn: PropTypes.bool,
  32. };
  33. componentWillMount () {
  34. this.props.dispatch(fetchMutes());
  35. }
  36. handleLoadMore = debounce(() => {
  37. this.props.dispatch(expandMutes());
  38. }, 300, { leading: true });
  39. render () {
  40. const { intl, shouldUpdateScroll, hasMore, accountIds, multiColumn } = this.props;
  41. if (!accountIds) {
  42. return (
  43. <Column>
  44. <LoadingIndicator />
  45. </Column>
  46. );
  47. }
  48. const emptyMessage = <FormattedMessage id='empty_column.mutes' defaultMessage="You haven't muted any users yet." />;
  49. return (
  50. <Column bindToDocument={!multiColumn} icon='volume-off' heading={intl.formatMessage(messages.heading)}>
  51. <ColumnBackButtonSlim />
  52. <ScrollableList
  53. scrollKey='mutes'
  54. onLoadMore={this.handleLoadMore}
  55. hasMore={hasMore}
  56. shouldUpdateScroll={shouldUpdateScroll}
  57. emptyMessage={emptyMessage}
  58. bindToDocument={!multiColumn}
  59. >
  60. {accountIds.map(id =>
  61. <AccountContainer key={id} id={id} />,
  62. )}
  63. </ScrollableList>
  64. </Column>
  65. );
  66. }
  67. }