The code powering m.abunchtell.com https://m.abunchtell.com
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.
 
 
 
 

75 rivejä
2.3 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. });
  21. @connect(mapStateToProps)
  22. @injectIntl
  23. export default class Blocks extends ImmutablePureComponent {
  24. static propTypes = {
  25. params: PropTypes.object.isRequired,
  26. dispatch: PropTypes.func.isRequired,
  27. shouldUpdateScroll: PropTypes.func,
  28. domains: ImmutablePropTypes.orderedSet,
  29. intl: PropTypes.object.isRequired,
  30. };
  31. componentWillMount () {
  32. this.props.dispatch(fetchDomainBlocks());
  33. }
  34. handleLoadMore = debounce(() => {
  35. this.props.dispatch(expandDomainBlocks());
  36. }, 300, { leading: true });
  37. render () {
  38. const { intl, domains, shouldUpdateScroll } = this.props;
  39. if (!domains) {
  40. return (
  41. <Column>
  42. <LoadingIndicator />
  43. </Column>
  44. );
  45. }
  46. const emptyMessage = <FormattedMessage id='empty_column.domain_blocks' defaultMessage='There are no hidden domains yet.' />;
  47. return (
  48. <Column icon='minus-circle' heading={intl.formatMessage(messages.heading)}>
  49. <ColumnBackButtonSlim />
  50. <ScrollableList
  51. scrollKey='domain_blocks'
  52. onLoadMore={this.handleLoadMore}
  53. shouldUpdateScroll={shouldUpdateScroll}
  54. emptyMessage={emptyMessage}
  55. >
  56. {domains.map(domain =>
  57. <DomainContainer key={domain} domain={domain} />
  58. )}
  59. </ScrollableList>
  60. </Column>
  61. );
  62. }
  63. }