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