index.jsx 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. import PropTypes from 'prop-types';
  2. import { defineMessages, injectIntl, FormattedMessage } from 'react-intl';
  3. import { Helmet } from 'react-helmet';
  4. import ImmutablePropTypes from 'react-immutable-proptypes';
  5. import ImmutablePureComponent from 'react-immutable-pure-component';
  6. import { connect } from 'react-redux';
  7. import { debounce } from 'lodash';
  8. import VolumeOffIcon from '@/material-icons/400-24px/volume_off.svg?react';
  9. import { fetchMutes, expandMutes } from '../../actions/mutes';
  10. import { LoadingIndicator } from '../../components/loading_indicator';
  11. import ScrollableList from '../../components/scrollable_list';
  12. import AccountContainer from '../../containers/account_container';
  13. import Column from '../ui/components/column';
  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. isLoading: state.getIn(['user_lists', 'mutes', 'isLoading'], true),
  21. });
  22. class Mutes extends ImmutablePureComponent {
  23. static propTypes = {
  24. params: PropTypes.object.isRequired,
  25. dispatch: PropTypes.func.isRequired,
  26. hasMore: PropTypes.bool,
  27. isLoading: PropTypes.bool,
  28. accountIds: ImmutablePropTypes.list,
  29. intl: PropTypes.object.isRequired,
  30. multiColumn: PropTypes.bool,
  31. };
  32. UNSAFE_componentWillMount () {
  33. this.props.dispatch(fetchMutes());
  34. }
  35. handleLoadMore = debounce(() => {
  36. this.props.dispatch(expandMutes());
  37. }, 300, { leading: true });
  38. render () {
  39. const { intl, hasMore, accountIds, multiColumn, isLoading } = this.props;
  40. if (!accountIds) {
  41. return (
  42. <Column>
  43. <LoadingIndicator />
  44. </Column>
  45. );
  46. }
  47. const emptyMessage = <FormattedMessage id='empty_column.mutes' defaultMessage="You haven't muted any users yet." />;
  48. return (
  49. <Column bindToDocument={!multiColumn} icon='volume-off' iconComponent={VolumeOffIcon} heading={intl.formatMessage(messages.heading)} alwaysShowBackButton>
  50. <ScrollableList
  51. scrollKey='mutes'
  52. onLoadMore={this.handleLoadMore}
  53. hasMore={hasMore}
  54. isLoading={isLoading}
  55. emptyMessage={emptyMessage}
  56. bindToDocument={!multiColumn}
  57. >
  58. {accountIds.map(id =>
  59. <AccountContainer key={id} id={id} defaultAction='mute' />,
  60. )}
  61. </ScrollableList>
  62. <Helmet>
  63. <meta name='robots' content='noindex' />
  64. </Helmet>
  65. </Column>
  66. );
  67. }
  68. }
  69. export default connect(mapStateToProps)(injectIntl(Mutes));