2016-11-14 06:42:54 +11:00
|
|
|
import { connect } from 'react-redux';
|
2017-04-22 04:05:35 +10:00
|
|
|
import PropTypes from 'prop-types';
|
2016-11-14 06:42:54 +11:00
|
|
|
import ImmutablePropTypes from 'react-immutable-proptypes';
|
|
|
|
import LoadingIndicator from '../../components/loading_indicator';
|
|
|
|
import {
|
2017-01-31 08:35:36 +11:00
|
|
|
fetchAccount,
|
2016-11-14 06:42:54 +11:00
|
|
|
fetchFollowing,
|
|
|
|
expandFollowing
|
|
|
|
} from '../../actions/accounts';
|
|
|
|
import { ScrollContainer } from 'react-router-scroll';
|
2016-11-21 05:39:18 +11:00
|
|
|
import AccountContainer from '../../containers/account_container';
|
2017-01-31 07:40:55 +11: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';
|
2016-10-28 06:59:56 +11:00
|
|
|
|
|
|
|
const mapStateToProps = (state, props) => ({
|
2016-11-14 06:42:54 +11:00
|
|
|
accountIds: state.getIn(['user_lists', 'following', Number(props.params.accountId), 'items'])
|
2016-10-28 06:59:56 +11:00
|
|
|
});
|
|
|
|
|
2017-04-22 04:05:35 +10:00
|
|
|
class Following extends React.PureComponent {
|
2016-10-28 06:59:56 +11:00
|
|
|
|
2017-04-22 04:05:35 +10:00
|
|
|
constructor (props, context) {
|
|
|
|
super(props, context);
|
|
|
|
this.handleScroll = this.handleScroll.bind(this);
|
|
|
|
this.handleLoadMore = this.handleLoadMore.bind(this);
|
|
|
|
}
|
2016-10-28 06:59:56 +11:00
|
|
|
|
|
|
|
componentWillMount () {
|
2017-01-31 08:35:36 +11:00
|
|
|
this.props.dispatch(fetchAccount(Number(this.props.params.accountId)));
|
2016-10-28 06:59:56 +11:00
|
|
|
this.props.dispatch(fetchFollowing(Number(this.props.params.accountId)));
|
2017-04-22 04:05:35 +10:00
|
|
|
}
|
2016-10-28 06:59:56 +11:00
|
|
|
|
|
|
|
componentWillReceiveProps(nextProps) {
|
|
|
|
if (nextProps.params.accountId !== this.props.params.accountId && nextProps.params.accountId) {
|
2017-01-31 08:35:36 +11:00
|
|
|
this.props.dispatch(fetchAccount(Number(nextProps.params.accountId)));
|
2016-10-28 06:59:56 +11:00
|
|
|
this.props.dispatch(fetchFollowing(Number(nextProps.params.accountId)));
|
|
|
|
}
|
2017-04-22 04:05:35 +10:00
|
|
|
}
|
2016-10-28 06:59:56 +11:00
|
|
|
|
2016-11-14 06:42:54 +11:00
|
|
|
handleScroll (e) {
|
|
|
|
const { scrollTop, scrollHeight, clientHeight } = e.target;
|
|
|
|
|
|
|
|
if (scrollTop === scrollHeight - clientHeight) {
|
|
|
|
this.props.dispatch(expandFollowing(Number(this.props.params.accountId)));
|
|
|
|
}
|
2017-04-22 04:05:35 +10:00
|
|
|
}
|
2016-11-14 06:42:54 +11:00
|
|
|
|
2017-01-31 07:40:55 +11:00
|
|
|
handleLoadMore (e) {
|
|
|
|
e.preventDefault();
|
|
|
|
this.props.dispatch(expandFollowing(Number(this.props.params.accountId)));
|
2017-04-22 04:05:35 +10:00
|
|
|
}
|
2017-01-31 07:40:55 +11:00
|
|
|
|
2016-10-28 06:59:56 +11:00
|
|
|
render () {
|
|
|
|
const { accountIds } = this.props;
|
|
|
|
|
|
|
|
if (!accountIds) {
|
2017-01-31 07:40:55 +11:00
|
|
|
return (
|
|
|
|
<Column>
|
|
|
|
<LoadingIndicator />
|
|
|
|
</Column>
|
|
|
|
);
|
2016-10-28 06:59:56 +11:00
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
2017-01-31 07:40:55 +11:00
|
|
|
<Column>
|
|
|
|
<ColumnBackButton />
|
2017-02-01 08:34:33 +11:00
|
|
|
|
2017-01-31 07:40:55 +11:00
|
|
|
<ScrollContainer scrollKey='following'>
|
|
|
|
<div className='scrollable' onScroll={this.handleScroll}>
|
2017-04-23 12:26:55 +10:00
|
|
|
<div className='following'>
|
2017-01-31 07:40:55 +11:00
|
|
|
<HeaderContainer accountId={this.props.params.accountId} />
|
|
|
|
{accountIds.map(id => <AccountContainer key={id} id={id} withNote={false} />)}
|
|
|
|
<LoadMore onClick={this.handleLoadMore} />
|
|
|
|
</div>
|
2016-11-14 06:42:54 +11:00
|
|
|
</div>
|
2017-01-31 07:40:55 +11:00
|
|
|
</ScrollContainer>
|
|
|
|
</Column>
|
2016-10-28 06:59:56 +11:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2017-04-22 04:05:35 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
Following.propTypes = {
|
|
|
|
params: PropTypes.object.isRequired,
|
|
|
|
dispatch: PropTypes.func.isRequired,
|
|
|
|
accountIds: ImmutablePropTypes.list
|
|
|
|
};
|
2016-10-28 06:59:56 +11:00
|
|
|
|
|
|
|
export default connect(mapStateToProps)(Following);
|