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

90 lines
2.7 KiB

  1. import { connect } from 'react-redux';
  2. import PropTypes from 'prop-types';
  3. import ImmutablePropTypes from 'react-immutable-proptypes';
  4. import LoadingIndicator from '../../components/loading_indicator';
  5. import {
  6. fetchAccount,
  7. fetchFollowing,
  8. expandFollowing
  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', 'following', Number(props.params.accountId), 'items'])
  18. });
  19. class Following extends React.PureComponent {
  20. constructor (props, context) {
  21. super(props, context);
  22. this.handleScroll = this.handleScroll.bind(this);
  23. this.handleLoadMore = this.handleLoadMore.bind(this);
  24. }
  25. componentWillMount () {
  26. this.props.dispatch(fetchAccount(Number(this.props.params.accountId)));
  27. this.props.dispatch(fetchFollowing(Number(this.props.params.accountId)));
  28. }
  29. componentWillReceiveProps(nextProps) {
  30. if (nextProps.params.accountId !== this.props.params.accountId && nextProps.params.accountId) {
  31. this.props.dispatch(fetchAccount(Number(nextProps.params.accountId)));
  32. this.props.dispatch(fetchFollowing(Number(nextProps.params.accountId)));
  33. }
  34. }
  35. handleScroll (e) {
  36. const { scrollTop, scrollHeight, clientHeight } = e.target;
  37. if (scrollTop === scrollHeight - clientHeight) {
  38. this.props.dispatch(expandFollowing(Number(this.props.params.accountId)));
  39. }
  40. }
  41. handleLoadMore (e) {
  42. e.preventDefault();
  43. this.props.dispatch(expandFollowing(Number(this.props.params.accountId)));
  44. }
  45. render () {
  46. const { accountIds } = this.props;
  47. if (!accountIds) {
  48. return (
  49. <Column>
  50. <LoadingIndicator />
  51. </Column>
  52. );
  53. }
  54. return (
  55. <Column>
  56. <ColumnBackButton />
  57. <ScrollContainer scrollKey='following'>
  58. <div className='scrollable' onScroll={this.handleScroll}>
  59. <div className='following'>
  60. <HeaderContainer accountId={this.props.params.accountId} />
  61. {accountIds.map(id => <AccountContainer key={id} id={id} withNote={false} />)}
  62. <LoadMore onClick={this.handleLoadMore} />
  63. </div>
  64. </div>
  65. </ScrollContainer>
  66. </Column>
  67. );
  68. }
  69. }
  70. Following.propTypes = {
  71. params: PropTypes.object.isRequired,
  72. dispatch: PropTypes.func.isRequired,
  73. accountIds: ImmutablePropTypes.list
  74. };
  75. export default connect(mapStateToProps)(Following);