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

86 lines
2.6 KiB

  1. import { connect } from 'react-redux';
  2. import PureRenderMixin from 'react-addons-pure-render-mixin';
  3. import ImmutablePropTypes from 'react-immutable-proptypes';
  4. import LoadingIndicator from '../../components/loading_indicator';
  5. import {
  6. fetchAccount,
  7. fetchFollowers,
  8. expandFollowers
  9. } from '../../actions/accounts';
  10. import { ScrollContainer } from 'react-router-scroll';
  11. import AccountContainer from '../../containers/account_container';
  12. import Column from '../ui/components/column';
  13. import HeaderContainer from '../account_timeline/containers/header_container';
  14. import LoadMore from '../../components/load_more';
  15. import ColumnBackButton from '../../components/column_back_button';
  16. const mapStateToProps = (state, props) => ({
  17. accountIds: state.getIn(['user_lists', 'followers', Number(props.params.accountId), 'items'])
  18. });
  19. const Followers = React.createClass({
  20. propTypes: {
  21. params: React.PropTypes.object.isRequired,
  22. dispatch: React.PropTypes.func.isRequired,
  23. accountIds: ImmutablePropTypes.list
  24. },
  25. mixins: [PureRenderMixin],
  26. componentWillMount () {
  27. this.props.dispatch(fetchAccount(Number(this.props.params.accountId)));
  28. this.props.dispatch(fetchFollowers(Number(this.props.params.accountId)));
  29. },
  30. componentWillReceiveProps(nextProps) {
  31. if (nextProps.params.accountId !== this.props.params.accountId && nextProps.params.accountId) {
  32. this.props.dispatch(fetchAccount(Number(nextProps.params.accountId)));
  33. this.props.dispatch(fetchFollowers(Number(nextProps.params.accountId)));
  34. }
  35. },
  36. handleScroll (e) {
  37. const { scrollTop, scrollHeight, clientHeight } = e.target;
  38. if (scrollTop === scrollHeight - clientHeight) {
  39. this.props.dispatch(expandFollowers(Number(this.props.params.accountId)));
  40. }
  41. },
  42. handleLoadMore (e) {
  43. e.preventDefault();
  44. this.props.dispatch(expandFollowing(Number(this.props.params.accountId)));
  45. },
  46. render () {
  47. const { accountIds } = this.props;
  48. if (!accountIds) {
  49. return (
  50. <Column>
  51. <LoadingIndicator />
  52. </Column>
  53. );
  54. }
  55. return (
  56. <Column>
  57. <ColumnBackButton />
  58. <ScrollContainer scrollKey='followers'>
  59. <div className='scrollable' onScroll={this.handleScroll}>
  60. <div>
  61. <HeaderContainer accountId={this.props.params.accountId} />
  62. {accountIds.map(id => <AccountContainer key={id} id={id} withNote={false} />)}
  63. <LoadMore onClick={this.handleLoadMore} />
  64. </div>
  65. </div>
  66. </ScrollContainer>
  67. </Column>
  68. );
  69. }
  70. });
  71. export default connect(mapStateToProps)(Followers);