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 PropTypes from 'prop-types';
  6. import ImmutablePropTypes from 'react-immutable-proptypes';
  7. import { debounce } from 'lodash';
  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 DomainContainer from '../../containers/domain_container';
  12. import { fetchDomainBlocks, expandDomainBlocks } from '../../actions/domain_blocks';
  13. import ScrollableList from '../../components/scrollable_list';
  14. const messages = defineMessages({
  15. heading: { id: 'column.domain_blocks', defaultMessage: 'Hidden domains' },
  16. unblockDomain: { id: 'account.unblock_domain', defaultMessage: 'Unhide {domain}' },
  17. });
  18. const mapStateToProps = state => ({
  19. domains: state.getIn(['domain_lists', 'blocks', 'items']),
  20. hasMore: !!state.getIn(['domain_lists', 'blocks', 'next']),
  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. hasMore: PropTypes.bool,
  30. domains: ImmutablePropTypes.orderedSet,
  31. intl: PropTypes.object.isRequired,
  32. multiColumn: PropTypes.bool,
  33. };
  34. componentWillMount () {
  35. this.props.dispatch(fetchDomainBlocks());
  36. }
  37. handleLoadMore = debounce(() => {
  38. this.props.dispatch(expandDomainBlocks());
  39. }, 300, { leading: true });
  40. render () {
  41. const { intl, domains, shouldUpdateScroll, hasMore, multiColumn } = this.props;
  42. if (!domains) {
  43. return (
  44. <Column>
  45. <LoadingIndicator />
  46. </Column>
  47. );
  48. }
  49. const emptyMessage = <FormattedMessage id='empty_column.domain_blocks' defaultMessage='There are no hidden domains yet.' />;
  50. return (
  51. <Column icon='minus-circle' heading={intl.formatMessage(messages.heading)}>
  52. <ColumnBackButtonSlim />
  53. <ScrollableList
  54. scrollKey='domain_blocks'
  55. onLoadMore={this.handleLoadMore}
  56. hasMore={hasMore}
  57. shouldUpdateScroll={shouldUpdateScroll}
  58. emptyMessage={emptyMessage}
  59. bindToDocument={!multiColumn}
  60. >
  61. {domains.map(domain =>
  62. <DomainContainer key={domain} domain={domain} />
  63. )}
  64. </ScrollableList>
  65. </Column>
  66. );
  67. }
  68. }