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

93 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. @connect(mapStateToProps)
  23. export default class Followers extends ImmutablePureComponent {
  24. static propTypes = {
  25. params: PropTypes.object.isRequired,
  26. dispatch: PropTypes.func.isRequired,
  27. accountIds: ImmutablePropTypes.list,
  28. hasMore: PropTypes.bool,
  29. };
  30. componentWillMount () {
  31. this.props.dispatch(fetchAccount(Number(this.props.params.accountId)));
  32. this.props.dispatch(fetchFollowers(Number(this.props.params.accountId)));
  33. }
  34. componentWillReceiveProps (nextProps) {
  35. if (nextProps.params.accountId !== this.props.params.accountId && nextProps.params.accountId) {
  36. this.props.dispatch(fetchAccount(Number(nextProps.params.accountId)));
  37. this.props.dispatch(fetchFollowers(Number(nextProps.params.accountId)));
  38. }
  39. }
  40. handleScroll = (e) => {
  41. const { scrollTop, scrollHeight, clientHeight } = e.target;
  42. if (scrollTop === scrollHeight - clientHeight && this.props.hasMore) {
  43. this.props.dispatch(expandFollowers(Number(this.props.params.accountId)));
  44. }
  45. }
  46. handleLoadMore = (e) => {
  47. e.preventDefault();
  48. this.props.dispatch(expandFollowers(Number(this.props.params.accountId)));
  49. }
  50. render () {
  51. const { accountIds, hasMore } = this.props;
  52. let loadMore = null;
  53. if (!accountIds) {
  54. return (
  55. <Column>
  56. <LoadingIndicator />
  57. </Column>
  58. );
  59. }
  60. if (hasMore) {
  61. loadMore = <LoadMore onClick={this.handleLoadMore} />;
  62. }
  63. return (
  64. <Column>
  65. <ColumnBackButton />
  66. <ScrollContainer scrollKey='followers'>
  67. <div className='scrollable' onScroll={this.handleScroll}>
  68. <div className='followers'>
  69. <HeaderContainer accountId={this.props.params.accountId} />
  70. {accountIds.map(id => <AccountContainer key={id} id={id} withNote={false} />)}
  71. {loadMore}
  72. </div>
  73. </div>
  74. </ScrollContainer>
  75. </Column>
  76. );
  77. }
  78. }