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.

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