index.js 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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. import { Helmet } from 'react-helmet';
  15. const messages = defineMessages({
  16. heading: { id: 'column.domain_blocks', defaultMessage: 'Blocked domains' },
  17. unblockDomain: { id: 'account.unblock_domain', defaultMessage: 'Unblock domain {domain}' },
  18. });
  19. const mapStateToProps = state => ({
  20. domains: state.getIn(['domain_lists', 'blocks', 'items']),
  21. hasMore: !!state.getIn(['domain_lists', 'blocks', 'next']),
  22. });
  23. export default @connect(mapStateToProps)
  24. @injectIntl
  25. class Blocks extends ImmutablePureComponent {
  26. static propTypes = {
  27. params: PropTypes.object.isRequired,
  28. dispatch: PropTypes.func.isRequired,
  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, 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 blocked domains yet.' />;
  50. return (
  51. <Column bindToDocument={!multiColumn} icon='minus-circle' heading={intl.formatMessage(messages.heading)}>
  52. <ColumnBackButtonSlim />
  53. <ScrollableList
  54. scrollKey='domain_blocks'
  55. onLoadMore={this.handleLoadMore}
  56. hasMore={hasMore}
  57. emptyMessage={emptyMessage}
  58. bindToDocument={!multiColumn}
  59. >
  60. {domains.map(domain =>
  61. <DomainContainer key={domain} domain={domain} />,
  62. )}
  63. </ScrollableList>
  64. <Helmet>
  65. <meta name='robots' content='noindex' />
  66. </Helmet>
  67. </Column>
  68. );
  69. }
  70. }