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