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

70 lines
2.0 KiB

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