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