闭社主体 forked from https://github.com/tootsuite/mastodon
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.

77 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: 'Blocked domains' },
  16. unblockDomain: { id: 'account.unblock_domain', defaultMessage: 'Unblock domain {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. hasMore: PropTypes.bool,
  29. domains: ImmutablePropTypes.orderedSet,
  30. intl: PropTypes.object.isRequired,
  31. multiColumn: PropTypes.bool,
  32. };
  33. componentWillMount () {
  34. this.props.dispatch(fetchDomainBlocks());
  35. }
  36. handleLoadMore = debounce(() => {
  37. this.props.dispatch(expandDomainBlocks());
  38. }, 300, { leading: true });
  39. render () {
  40. const { intl, domains, hasMore, multiColumn } = this.props;
  41. if (!domains) {
  42. return (
  43. <Column>
  44. <LoadingIndicator />
  45. </Column>
  46. );
  47. }
  48. const emptyMessage = <FormattedMessage id='empty_column.domain_blocks' defaultMessage='There are no blocked domains yet.' />;
  49. return (
  50. <Column bindToDocument={!multiColumn} icon='minus-circle' heading={intl.formatMessage(messages.heading)}>
  51. <ColumnBackButtonSlim />
  52. <ScrollableList
  53. scrollKey='domain_blocks'
  54. onLoadMore={this.handleLoadMore}
  55. hasMore={hasMore}
  56. emptyMessage={emptyMessage}
  57. bindToDocument={!multiColumn}
  58. >
  59. {domains.map(domain =>
  60. <DomainContainer key={domain} domain={domain} />,
  61. )}
  62. </ScrollableList>
  63. </Column>
  64. );
  65. }
  66. }