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.

79 lines
2.5 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. accountIds: ImmutablePropTypes.list,
  29. hasMore: PropTypes.bool,
  30. isLoading: PropTypes.bool,
  31. intl: PropTypes.object.isRequired,
  32. multiColumn: PropTypes.bool,
  33. };
  34. componentWillMount () {
  35. this.props.dispatch(fetchBlocks());
  36. }
  37. handleLoadMore = debounce(() => {
  38. this.props.dispatch(expandBlocks());
  39. }, 300, { leading: true });
  40. render () {
  41. const { intl, accountIds, hasMore, multiColumn, isLoading } = this.props;
  42. if (!accountIds) {
  43. return (
  44. <Column>
  45. <LoadingIndicator />
  46. </Column>
  47. );
  48. }
  49. const emptyMessage = <FormattedMessage id='empty_column.blocks' defaultMessage="You haven't blocked any users yet." />;
  50. return (
  51. <Column bindToDocument={!multiColumn} icon='ban' heading={intl.formatMessage(messages.heading)}>
  52. <ColumnBackButtonSlim />
  53. <ScrollableList
  54. scrollKey='blocks'
  55. onLoadMore={this.handleLoadMore}
  56. hasMore={hasMore}
  57. isLoading={isLoading}
  58. emptyMessage={emptyMessage}
  59. bindToDocument={!multiColumn}
  60. >
  61. {accountIds.map(id =>
  62. <AccountContainer key={id} id={id} />,
  63. )}
  64. </ScrollableList>
  65. </Column>
  66. );
  67. }
  68. }