2017-05-02 20:04:16 -04:00
|
|
|
import React from 'react';
|
2016-11-13 14:42:54 -05:00
|
|
|
import { connect } from 'react-redux';
|
2017-04-21 14:05:35 -04:00
|
|
|
import PropTypes from 'prop-types';
|
2016-11-13 14:42:54 -05:00
|
|
|
import ImmutablePropTypes from 'react-immutable-proptypes';
|
|
|
|
import LoadingIndicator from '../../components/loading_indicator';
|
|
|
|
import {
|
2017-01-30 16:35:36 -05:00
|
|
|
fetchAccount,
|
2016-11-13 14:42:54 -05:00
|
|
|
fetchFollowers,
|
2017-05-20 11:31:47 -04:00
|
|
|
expandFollowers,
|
2016-11-13 14:42:54 -05:00
|
|
|
} from '../../actions/accounts';
|
|
|
|
import { ScrollContainer } from 'react-router-scroll';
|
2016-11-20 13:39:18 -05:00
|
|
|
import AccountContainer from '../../containers/account_container';
|
2017-01-30 15:40:55 -05:00
|
|
|
import Column from '../ui/components/column';
|
|
|
|
import HeaderContainer from '../account_timeline/containers/header_container';
|
|
|
|
import LoadMore from '../../components/load_more';
|
|
|
|
import ColumnBackButton from '../../components/column_back_button';
|
2017-05-02 20:04:16 -04:00
|
|
|
import ImmutablePureComponent from 'react-immutable-pure-component';
|
2016-10-27 15:59:56 -04:00
|
|
|
|
|
|
|
const mapStateToProps = (state, props) => ({
|
2017-05-20 11:31:47 -04:00
|
|
|
accountIds: state.getIn(['user_lists', 'followers', Number(props.params.accountId), 'items']),
|
2017-06-05 08:13:20 -04:00
|
|
|
hasMore: !!state.getIn(['user_lists', 'followers', Number(props.params.accountId), 'next']),
|
2016-10-27 15:59:56 -04:00
|
|
|
});
|
|
|
|
|
2017-05-02 20:04:16 -04:00
|
|
|
class Followers extends ImmutablePureComponent {
|
2016-10-27 15:59:56 -04:00
|
|
|
|
2017-05-12 08:44:10 -04:00
|
|
|
static propTypes = {
|
|
|
|
params: PropTypes.object.isRequired,
|
|
|
|
dispatch: PropTypes.func.isRequired,
|
2017-05-20 11:31:47 -04:00
|
|
|
accountIds: ImmutablePropTypes.list,
|
2017-06-05 12:18:56 -04:00
|
|
|
hasMore: PropTypes.bool,
|
2017-05-12 08:44:10 -04:00
|
|
|
};
|
2016-10-27 15:59:56 -04:00
|
|
|
|
|
|
|
componentWillMount () {
|
2017-01-30 16:35:36 -05:00
|
|
|
this.props.dispatch(fetchAccount(Number(this.props.params.accountId)));
|
2016-10-27 15:59:56 -04:00
|
|
|
this.props.dispatch(fetchFollowers(Number(this.props.params.accountId)));
|
2017-04-21 14:05:35 -04:00
|
|
|
}
|
2016-10-27 15:59:56 -04:00
|
|
|
|
2017-05-12 08:44:10 -04:00
|
|
|
componentWillReceiveProps (nextProps) {
|
2016-10-27 15:59:56 -04:00
|
|
|
if (nextProps.params.accountId !== this.props.params.accountId && nextProps.params.accountId) {
|
2017-01-30 16:35:36 -05:00
|
|
|
this.props.dispatch(fetchAccount(Number(nextProps.params.accountId)));
|
2016-10-27 15:59:56 -04:00
|
|
|
this.props.dispatch(fetchFollowers(Number(nextProps.params.accountId)));
|
|
|
|
}
|
2017-04-21 14:05:35 -04:00
|
|
|
}
|
2016-10-27 15:59:56 -04:00
|
|
|
|
2017-05-12 08:44:10 -04:00
|
|
|
handleScroll = (e) => {
|
2016-11-13 14:42:54 -05:00
|
|
|
const { scrollTop, scrollHeight, clientHeight } = e.target;
|
|
|
|
|
2017-06-05 12:18:56 -04:00
|
|
|
if (scrollTop === scrollHeight - clientHeight && this.props.hasMore) {
|
2016-11-13 14:42:54 -05:00
|
|
|
this.props.dispatch(expandFollowers(Number(this.props.params.accountId)));
|
|
|
|
}
|
2017-04-21 14:05:35 -04:00
|
|
|
}
|
2016-11-13 14:42:54 -05:00
|
|
|
|
2017-05-12 08:44:10 -04:00
|
|
|
handleLoadMore = (e) => {
|
2017-01-30 15:40:55 -05:00
|
|
|
e.preventDefault();
|
2017-04-15 10:41:22 -04:00
|
|
|
this.props.dispatch(expandFollowers(Number(this.props.params.accountId)));
|
2017-04-21 14:05:35 -04:00
|
|
|
}
|
2017-01-30 15:40:55 -05:00
|
|
|
|
2016-10-27 15:59:56 -04:00
|
|
|
render () {
|
2017-06-05 08:13:20 -04:00
|
|
|
const { accountIds, hasMore } = this.props;
|
|
|
|
|
|
|
|
let loadMore = null;
|
2016-10-27 15:59:56 -04:00
|
|
|
|
|
|
|
if (!accountIds) {
|
2017-01-30 15:40:55 -05:00
|
|
|
return (
|
|
|
|
<Column>
|
|
|
|
<LoadingIndicator />
|
|
|
|
</Column>
|
|
|
|
);
|
2016-10-27 15:59:56 -04:00
|
|
|
}
|
|
|
|
|
2017-06-05 08:13:20 -04:00
|
|
|
if (hasMore) {
|
|
|
|
loadMore = <LoadMore onClick={this.handleLoadMore} />;
|
|
|
|
}
|
|
|
|
|
2016-10-27 15:59:56 -04:00
|
|
|
return (
|
2017-01-30 15:40:55 -05:00
|
|
|
<Column>
|
|
|
|
<ColumnBackButton />
|
2017-01-31 16:34:33 -05:00
|
|
|
|
2017-01-30 15:40:55 -05:00
|
|
|
<ScrollContainer scrollKey='followers'>
|
|
|
|
<div className='scrollable' onScroll={this.handleScroll}>
|
2017-04-22 22:26:55 -04:00
|
|
|
<div className='followers'>
|
2017-01-30 15:40:55 -05:00
|
|
|
<HeaderContainer accountId={this.props.params.accountId} />
|
|
|
|
{accountIds.map(id => <AccountContainer key={id} id={id} withNote={false} />)}
|
2017-06-05 08:13:20 -04:00
|
|
|
{loadMore}
|
2017-01-30 15:40:55 -05:00
|
|
|
</div>
|
2016-11-13 14:42:54 -05:00
|
|
|
</div>
|
2017-01-30 15:40:55 -05:00
|
|
|
</ScrollContainer>
|
|
|
|
</Column>
|
2016-10-27 15:59:56 -04:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2017-04-21 14:05:35 -04:00
|
|
|
}
|
|
|
|
|
2016-10-27 15:59:56 -04:00
|
|
|
export default connect(mapStateToProps)(Followers);
|