index.jsx 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. import PropTypes from 'prop-types';
  2. import { defineMessages, injectIntl, FormattedMessage } from 'react-intl';
  3. import ImmutablePropTypes from 'react-immutable-proptypes';
  4. import ImmutablePureComponent from 'react-immutable-pure-component';
  5. import { connect } from 'react-redux';
  6. import { debounce } from 'lodash';
  7. import BlockIcon from '@/material-icons/400-24px/block-fill.svg?react';
  8. import { fetchBlocks, expandBlocks } from '../../actions/blocks';
  9. import { LoadingIndicator } from '../../components/loading_indicator';
  10. import ScrollableList from '../../components/scrollable_list';
  11. import AccountContainer from '../../containers/account_container';
  12. import Column from '../ui/components/column';
  13. const messages = defineMessages({
  14. heading: { id: 'column.blocks', defaultMessage: 'Blocked users' },
  15. });
  16. const mapStateToProps = state => ({
  17. accountIds: state.getIn(['user_lists', 'blocks', 'items']),
  18. hasMore: !!state.getIn(['user_lists', 'blocks', 'next']),
  19. isLoading: state.getIn(['user_lists', 'blocks', 'isLoading'], true),
  20. });
  21. class Blocks extends ImmutablePureComponent {
  22. static propTypes = {
  23. params: PropTypes.object.isRequired,
  24. dispatch: PropTypes.func.isRequired,
  25. accountIds: ImmutablePropTypes.list,
  26. hasMore: PropTypes.bool,
  27. isLoading: PropTypes.bool,
  28. intl: PropTypes.object.isRequired,
  29. multiColumn: PropTypes.bool,
  30. };
  31. UNSAFE_componentWillMount () {
  32. this.props.dispatch(fetchBlocks());
  33. }
  34. handleLoadMore = debounce(() => {
  35. this.props.dispatch(expandBlocks());
  36. }, 300, { leading: true });
  37. render () {
  38. const { intl, accountIds, hasMore, multiColumn, isLoading } = this.props;
  39. if (!accountIds) {
  40. return (
  41. <Column>
  42. <LoadingIndicator />
  43. </Column>
  44. );
  45. }
  46. const emptyMessage = <FormattedMessage id='empty_column.blocks' defaultMessage="You haven't blocked any users yet." />;
  47. return (
  48. <Column bindToDocument={!multiColumn} icon='ban' iconComponent={BlockIcon} heading={intl.formatMessage(messages.heading)} alwaysShowBackButton>
  49. <ScrollableList
  50. scrollKey='blocks'
  51. onLoadMore={this.handleLoadMore}
  52. hasMore={hasMore}
  53. isLoading={isLoading}
  54. emptyMessage={emptyMessage}
  55. bindToDocument={!multiColumn}
  56. >
  57. {accountIds.map(id =>
  58. <AccountContainer key={id} id={id} defaultAction='block' />,
  59. )}
  60. </ScrollableList>
  61. </Column>
  62. );
  63. }
  64. }
  65. export default connect(mapStateToProps)(injectIntl(Blocks));