index.js 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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. export default @connect(mapStateToProps)
  24. @injectIntl
  25. class Mutes extends ImmutablePureComponent {
  26. static propTypes = {
  27. params: PropTypes.object.isRequired,
  28. dispatch: PropTypes.func.isRequired,
  29. hasMore: PropTypes.bool,
  30. isLoading: PropTypes.bool,
  31. accountIds: ImmutablePropTypes.list,
  32. intl: PropTypes.object.isRequired,
  33. multiColumn: PropTypes.bool,
  34. };
  35. componentWillMount () {
  36. this.props.dispatch(fetchMutes());
  37. }
  38. handleLoadMore = debounce(() => {
  39. this.props.dispatch(expandMutes());
  40. }, 300, { leading: true });
  41. render () {
  42. const { intl, hasMore, accountIds, multiColumn, isLoading } = this.props;
  43. if (!accountIds) {
  44. return (
  45. <Column>
  46. <LoadingIndicator />
  47. </Column>
  48. );
  49. }
  50. const emptyMessage = <FormattedMessage id='empty_column.mutes' defaultMessage="You haven't muted any users yet." />;
  51. return (
  52. <Column bindToDocument={!multiColumn} icon='volume-off' heading={intl.formatMessage(messages.heading)}>
  53. <ColumnBackButtonSlim />
  54. <ScrollableList
  55. scrollKey='mutes'
  56. onLoadMore={this.handleLoadMore}
  57. hasMore={hasMore}
  58. isLoading={isLoading}
  59. emptyMessage={emptyMessage}
  60. bindToDocument={!multiColumn}
  61. >
  62. {accountIds.map(id =>
  63. <AccountContainer key={id} id={id} defaultAction='mute' />,
  64. )}
  65. </ScrollableList>
  66. <Helmet>
  67. <meta name='robots' content='noindex' />
  68. </Helmet>
  69. </Column>
  70. );
  71. }
  72. }