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,
|
2017-05-20 18:31:47 +03:00
|
|
|
expandFollowing,
|
2016-11-13 21:42:54 +02:00
|
|
|
} 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) => ({
|
2017-05-20 18:31:47 +03:00
|
|
|
accountIds: state.getIn(['user_lists', 'following', Number(props.params.accountId), 'items']),
|
2017-06-05 15:13:20 +03:00
|
|
|
hasMore: !!state.getIn(['user_lists', 'following', Number(props.params.accountId), 'next']),
|
2016-10-27 22:59:56 +03:00
|
|
|
});
|
|
|
|
|
2017-06-23 20:36:54 +03:00
|
|
|
@connect(mapStateToProps)
|
|
|
|
export default 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,
|
2017-05-20 18:31:47 +03:00
|
|
|
accountIds: ImmutablePropTypes.list,
|
2017-06-05 19:18:56 +03:00
|
|
|
hasMore: PropTypes.bool,
|
2017-05-12 15:44:10 +03:00
|
|
|
};
|
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;
|
|
|
|
|
2017-06-05 19:18:56 +03:00
|
|
|
if (scrollTop === scrollHeight - clientHeight && this.props.hasMore) {
|
2016-11-13 21:42:54 +02:00
|
|
|
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 () {
|
2017-06-05 15:13:20 +03:00
|
|
|
const { accountIds, hasMore } = this.props;
|
|
|
|
|
|
|
|
let loadMore = null;
|
2016-10-27 22:59:56 +03:00
|
|
|
|
|
|
|
if (!accountIds) {
|
2017-01-30 22:40:55 +02:00
|
|
|
return (
|
|
|
|
<Column>
|
|
|
|
<LoadingIndicator />
|
|
|
|
</Column>
|
|
|
|
);
|
2016-10-27 22:59:56 +03:00
|
|
|
}
|
|
|
|
|
2017-06-05 15:13:20 +03:00
|
|
|
if (hasMore) {
|
|
|
|
loadMore = <LoadMore onClick={this.handleLoadMore} />;
|
|
|
|
}
|
|
|
|
|
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} />)}
|
2017-06-05 15:13:20 +03:00
|
|
|
{loadMore}
|
2017-01-30 22:40:55 +02:00
|
|
|
</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
|
|
|
}
|