The code powering m.abunchtell.com https://m.abunchtell.com
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.
 
 
 
 

65 lines
1.8 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. fetchFollowers,
  7. expandFollowers
  8. } from '../../actions/accounts';
  9. import { ScrollContainer } from 'react-router-scroll';
  10. import AccountContainer from '../../containers/account_container';
  11. const mapStateToProps = (state, props) => ({
  12. accountIds: state.getIn(['user_lists', 'followers', Number(props.params.accountId), 'items'])
  13. });
  14. const Followers = React.createClass({
  15. propTypes: {
  16. params: React.PropTypes.object.isRequired,
  17. dispatch: React.PropTypes.func.isRequired,
  18. accountIds: ImmutablePropTypes.list
  19. },
  20. mixins: [PureRenderMixin],
  21. componentWillMount () {
  22. this.props.dispatch(fetchFollowers(Number(this.props.params.accountId)));
  23. },
  24. componentWillReceiveProps(nextProps) {
  25. if (nextProps.params.accountId !== this.props.params.accountId && nextProps.params.accountId) {
  26. this.props.dispatch(fetchFollowers(Number(nextProps.params.accountId)));
  27. }
  28. },
  29. handleScroll (e) {
  30. const { scrollTop, scrollHeight, clientHeight } = e.target;
  31. if (scrollTop === scrollHeight - clientHeight) {
  32. this.props.dispatch(expandFollowers(Number(this.props.params.accountId)));
  33. }
  34. },
  35. render () {
  36. const { accountIds } = this.props;
  37. if (!accountIds) {
  38. return <LoadingIndicator />;
  39. }
  40. return (
  41. <ScrollContainer scrollKey='followers'>
  42. <div className='scrollable' onScroll={this.handleScroll}>
  43. <div>
  44. {accountIds.map(id => <AccountContainer key={id} id={id} withNote={false} />)}
  45. </div>
  46. </div>
  47. </ScrollContainer>
  48. );
  49. }
  50. });
  51. export default connect(mapStateToProps)(Followers);