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.6 KiB

  1. import React from 'react';
  2. import { connect } from 'react-redux';
  3. import ImmutablePropTypes from 'react-immutable-proptypes';
  4. import { debounce } from 'lodash';
  5. import PropTypes from 'prop-types';
  6. import LoadingIndicator from 'flavours/glitch/components/loading_indicator';
  7. import ScrollableList from '../../components/scrollable_list';
  8. import Column from 'flavours/glitch/features/ui/components/column';
  9. import ColumnBackButtonSlim from 'flavours/glitch/components/column_back_button_slim';
  10. import AccountContainer from 'flavours/glitch/containers/account_container';
  11. import { fetchBlocks, expandBlocks } from 'flavours/glitch/actions/blocks';
  12. import { defineMessages, injectIntl, FormattedMessage } from 'react-intl';
  13. import ImmutablePureComponent from 'react-immutable-pure-component';
  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. class Blocks extends ImmutablePureComponent {
  23. static propTypes = {
  24. params: PropTypes.object.isRequired,
  25. dispatch: PropTypes.func.isRequired,
  26. accountIds: ImmutablePropTypes.list,
  27. hasMore: PropTypes.bool,
  28. isLoading: PropTypes.bool,
  29. intl: PropTypes.object.isRequired,
  30. multiColumn: PropTypes.bool,
  31. };
  32. componentWillMount () {
  33. this.props.dispatch(fetchBlocks());
  34. }
  35. handleLoadMore = debounce(() => {
  36. this.props.dispatch(expandBlocks());
  37. }, 300, { leading: true });
  38. render () {
  39. const { intl, accountIds, hasMore, multiColumn, isLoading } = this.props;
  40. if (!accountIds) {
  41. return (
  42. <Column>
  43. <LoadingIndicator />
  44. </Column>
  45. );
  46. }
  47. const emptyMessage = <FormattedMessage id='empty_column.blocks' defaultMessage="You haven't blocked any users yet." />;
  48. return (
  49. <Column name='blocks' bindToDocument={!multiColumn} icon='ban' heading={intl.formatMessage(messages.heading)}>
  50. <ColumnBackButtonSlim />
  51. <ScrollableList
  52. scrollKey='blocks'
  53. onLoadMore={this.handleLoadMore}
  54. hasMore={hasMore}
  55. isLoading={isLoading}
  56. emptyMessage={emptyMessage}
  57. bindToDocument={!multiColumn}
  58. >
  59. {accountIds.map(id =>
  60. <AccountContainer key={id} id={id} defaultAction='block' />,
  61. )}
  62. </ScrollableList>
  63. </Column>
  64. );
  65. }
  66. }
  67. export default connect(mapStateToProps)(injectIntl(Blocks));