2017-05-03 02:04:16 +02:00
|
|
|
import React from 'react';
|
2016-11-16 17:20:52 +01:00
|
|
|
import { connect } from 'react-redux';
|
|
|
|
import ImmutablePropTypes from 'react-immutable-proptypes';
|
2017-04-21 20:05:35 +02:00
|
|
|
import PropTypes from 'prop-types';
|
2017-06-11 17:07:35 +02:00
|
|
|
import { fetchAccount } from '../../actions/accounts';
|
|
|
|
import { refreshAccountTimeline, expandAccountTimeline } from '../../actions/timelines';
|
2016-11-16 17:20:52 +01:00
|
|
|
import StatusList from '../../components/status_list';
|
|
|
|
import LoadingIndicator from '../../components/loading_indicator';
|
2017-01-30 21:40:55 +01:00
|
|
|
import Column from '../ui/components/column';
|
|
|
|
import HeaderContainer from './containers/header_container';
|
|
|
|
import ColumnBackButton from '../../components/column_back_button';
|
2017-07-11 01:00:14 +02:00
|
|
|
import { List as ImmutableList } from 'immutable';
|
2017-05-03 02:04:16 +02:00
|
|
|
import ImmutablePureComponent from 'react-immutable-pure-component';
|
2016-10-09 20:18:54 +02:00
|
|
|
|
|
|
|
const mapStateToProps = (state, props) => ({
|
2017-07-11 01:00:14 +02:00
|
|
|
statusIds: state.getIn(['timelines', `account:${Number(props.params.accountId)}`, 'items'], ImmutableList()),
|
2017-06-11 17:07:35 +02:00
|
|
|
isLoading: state.getIn(['timelines', `account:${Number(props.params.accountId)}`, 'isLoading']),
|
|
|
|
hasMore: !!state.getIn(['timelines', `account:${Number(props.params.accountId)}`, 'next']),
|
2017-05-20 17:31:47 +02:00
|
|
|
me: state.getIn(['meta', 'me']),
|
2016-10-09 20:18:54 +02:00
|
|
|
});
|
|
|
|
|
2017-06-23 19:36:54 +02:00
|
|
|
@connect(mapStateToProps)
|
|
|
|
export default class AccountTimeline extends ImmutablePureComponent {
|
2016-10-09 20:18:54 +02:00
|
|
|
|
2017-05-12 14:44:10 +02:00
|
|
|
static propTypes = {
|
|
|
|
params: PropTypes.object.isRequired,
|
|
|
|
dispatch: PropTypes.func.isRequired,
|
|
|
|
statusIds: ImmutablePropTypes.list,
|
|
|
|
isLoading: PropTypes.bool,
|
|
|
|
hasMore: PropTypes.bool,
|
2017-05-20 17:31:47 +02:00
|
|
|
me: PropTypes.number.isRequired,
|
2017-05-12 14:44:10 +02:00
|
|
|
};
|
2016-10-09 20:18:54 +02:00
|
|
|
|
|
|
|
componentWillMount () {
|
2017-01-30 22:35:36 +01:00
|
|
|
this.props.dispatch(fetchAccount(Number(this.props.params.accountId)));
|
2017-06-11 17:07:35 +02:00
|
|
|
this.props.dispatch(refreshAccountTimeline(Number(this.props.params.accountId)));
|
2017-04-21 20:05:35 +02:00
|
|
|
}
|
2016-10-09 20:18:54 +02:00
|
|
|
|
2017-05-12 14:44:10 +02:00
|
|
|
componentWillReceiveProps (nextProps) {
|
2016-10-09 20:18:54 +02:00
|
|
|
if (nextProps.params.accountId !== this.props.params.accountId && nextProps.params.accountId) {
|
2017-01-30 22:35:36 +01:00
|
|
|
this.props.dispatch(fetchAccount(Number(nextProps.params.accountId)));
|
2017-06-11 17:07:35 +02:00
|
|
|
this.props.dispatch(refreshAccountTimeline(Number(nextProps.params.accountId)));
|
2016-10-09 20:18:54 +02:00
|
|
|
}
|
2017-04-21 20:05:35 +02:00
|
|
|
}
|
2016-10-09 20:18:54 +02:00
|
|
|
|
2017-05-12 14:44:10 +02:00
|
|
|
handleScrollToBottom = () => {
|
2017-04-18 13:10:49 +02:00
|
|
|
if (!this.props.isLoading && this.props.hasMore) {
|
|
|
|
this.props.dispatch(expandAccountTimeline(Number(this.props.params.accountId)));
|
|
|
|
}
|
2017-04-21 20:05:35 +02:00
|
|
|
}
|
2016-10-09 20:18:54 +02:00
|
|
|
|
|
|
|
render () {
|
2017-02-22 16:30:09 +01:00
|
|
|
const { statusIds, isLoading, hasMore, me } = this.props;
|
2016-10-24 17:11:02 +02:00
|
|
|
|
2017-01-31 22:34:33 +01:00
|
|
|
if (!statusIds && isLoading) {
|
2017-01-30 21:40:55 +01:00
|
|
|
return (
|
|
|
|
<Column>
|
|
|
|
<LoadingIndicator />
|
|
|
|
</Column>
|
|
|
|
);
|
2016-10-24 17:11:02 +02:00
|
|
|
}
|
2016-10-09 20:18:54 +02:00
|
|
|
|
2017-01-30 21:40:55 +01:00
|
|
|
return (
|
2017-08-06 21:27:47 +02:00
|
|
|
<Column name='account'>
|
2017-01-30 21:40:55 +01:00
|
|
|
<ColumnBackButton />
|
|
|
|
|
|
|
|
<StatusList
|
|
|
|
prepend={<HeaderContainer accountId={this.props.params.accountId} />}
|
2017-04-24 04:49:08 +02:00
|
|
|
scrollKey='account_timeline'
|
2017-01-30 21:40:55 +01:00
|
|
|
statusIds={statusIds}
|
|
|
|
isLoading={isLoading}
|
2017-02-22 16:30:09 +01:00
|
|
|
hasMore={hasMore}
|
2017-01-30 21:40:55 +01:00
|
|
|
me={me}
|
|
|
|
onScrollToBottom={this.handleScrollToBottom}
|
|
|
|
/>
|
|
|
|
</Column>
|
|
|
|
);
|
2016-10-09 20:18:54 +02:00
|
|
|
}
|
|
|
|
|
2017-04-21 20:05:35 +02:00
|
|
|
}
|