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

94 lines
2.9 KiB

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