闭社主体 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.

72 lines
2.0 KiB

  1. import { connect } from 'react-redux';
  2. import ImmutablePropTypes from 'react-immutable-proptypes';
  3. import PropTypes from 'prop-types';
  4. import LoadingIndicator from '../../components/loading_indicator';
  5. import { ScrollContainer } from 'react-router-scroll';
  6. import Column from '../ui/components/column';
  7. import ColumnBackButtonSlim from '../../components/column_back_button_slim';
  8. import AccountContainer from '../../containers/account_container';
  9. import { fetchBlocks, expandBlocks } from '../../actions/blocks';
  10. import { defineMessages, injectIntl } from 'react-intl';
  11. const messages = defineMessages({
  12. heading: { id: 'column.blocks', defaultMessage: 'Blocked users' }
  13. });
  14. const mapStateToProps = state => ({
  15. accountIds: state.getIn(['user_lists', 'blocks', 'items'])
  16. });
  17. class Blocks extends React.PureComponent {
  18. constructor (props, context) {
  19. super(props, context);
  20. this.handleScroll = this.handleScroll.bind(this);
  21. }
  22. componentWillMount () {
  23. this.props.dispatch(fetchBlocks());
  24. }
  25. handleScroll (e) {
  26. const { scrollTop, scrollHeight, clientHeight } = e.target;
  27. if (scrollTop === scrollHeight - clientHeight) {
  28. this.props.dispatch(expandBlocks());
  29. }
  30. }
  31. render () {
  32. const { intl, accountIds } = this.props;
  33. if (!accountIds) {
  34. return (
  35. <Column>
  36. <LoadingIndicator />
  37. </Column>
  38. );
  39. }
  40. return (
  41. <Column icon='ban' heading={intl.formatMessage(messages.heading)}>
  42. <ColumnBackButtonSlim />
  43. <ScrollContainer scrollKey='blocks'>
  44. <div className='scrollable' onScroll={this.handleScroll}>
  45. {accountIds.map(id =>
  46. <AccountContainer key={id} id={id} />
  47. )}
  48. </div>
  49. </ScrollContainer>
  50. </Column>
  51. );
  52. }
  53. }
  54. Blocks.propTypes = {
  55. params: PropTypes.object.isRequired,
  56. dispatch: PropTypes.func.isRequired,
  57. accountIds: ImmutablePropTypes.list,
  58. intl: PropTypes.object.isRequired
  59. };
  60. export default connect(mapStateToProps)(injectIntl(Blocks));