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.

84 lines
2.6 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. import { Helmet } from 'react-helmet';
  15. const messages = defineMessages({
  16. heading: { id: 'column.mutes', defaultMessage: 'Muted users' },
  17. });
  18. const mapStateToProps = state => ({
  19. accountIds: state.getIn(['user_lists', 'mutes', 'items']),
  20. hasMore: !!state.getIn(['user_lists', 'mutes', 'next']),
  21. isLoading: state.getIn(['user_lists', 'mutes', 'isLoading'], true),
  22. });
  23. class Mutes extends ImmutablePureComponent {
  24. static propTypes = {
  25. params: PropTypes.object.isRequired,
  26. dispatch: PropTypes.func.isRequired,
  27. hasMore: PropTypes.bool,
  28. isLoading: 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, hasMore, accountIds, multiColumn, isLoading } = 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. isLoading={isLoading}
  57. emptyMessage={emptyMessage}
  58. bindToDocument={!multiColumn}
  59. >
  60. {accountIds.map(id =>
  61. <AccountContainer key={id} id={id} defaultAction='mute' />,
  62. )}
  63. </ScrollableList>
  64. <Helmet>
  65. <meta name='robots' content='noindex' />
  66. </Helmet>
  67. </Column>
  68. );
  69. }
  70. }
  71. export default connect(mapStateToProps)(injectIntl(Mutes));