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