2016-11-17 03:20:52 +11:00
|
|
|
import { connect } from 'react-redux';
|
|
|
|
import PureRenderMixin from 'react-addons-pure-render-mixin';
|
|
|
|
import ImmutablePropTypes from 'react-immutable-proptypes';
|
2016-10-10 05:18:54 +11:00
|
|
|
import {
|
|
|
|
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';
|
2016-10-10 05:18:54 +11:00
|
|
|
|
|
|
|
const mapStateToProps = (state, props) => ({
|
2017-01-24 14:12:10 +11:00
|
|
|
statusIds: state.getIn(['timelines', 'accounts_timelines', Number(props.params.accountId), 'items']),
|
|
|
|
isLoading: state.getIn(['timelines', 'accounts_timelines', Number(props.params.accountId), 'isLoading']),
|
2016-10-31 01:06:43 +11:00
|
|
|
me: state.getIn(['meta', 'me'])
|
2016-10-10 05:18:54 +11:00
|
|
|
});
|
|
|
|
|
|
|
|
const AccountTimeline = React.createClass({
|
|
|
|
|
|
|
|
propTypes: {
|
|
|
|
params: React.PropTypes.object.isRequired,
|
|
|
|
dispatch: React.PropTypes.func.isRequired,
|
2017-01-16 23:27:58 +11:00
|
|
|
statusIds: ImmutablePropTypes.list,
|
2017-01-24 14:12:10 +11:00
|
|
|
isLoading: React.PropTypes.bool,
|
2017-01-16 23:27:58 +11:00
|
|
|
me: React.PropTypes.number.isRequired
|
2016-10-10 05:18:54 +11:00
|
|
|
},
|
|
|
|
|
|
|
|
mixins: [PureRenderMixin],
|
|
|
|
|
|
|
|
componentWillMount () {
|
|
|
|
this.props.dispatch(fetchAccountTimeline(Number(this.props.params.accountId)));
|
|
|
|
},
|
|
|
|
|
|
|
|
componentWillReceiveProps(nextProps) {
|
|
|
|
if (nextProps.params.accountId !== this.props.params.accountId && nextProps.params.accountId) {
|
|
|
|
this.props.dispatch(fetchAccountTimeline(Number(nextProps.params.accountId)));
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
handleScrollToBottom () {
|
2016-10-17 10:23:41 +11:00
|
|
|
this.props.dispatch(expandAccountTimeline(Number(this.props.params.accountId)));
|
2016-10-10 05:18:54 +11:00
|
|
|
},
|
|
|
|
|
|
|
|
render () {
|
2017-01-24 14:12:10 +11:00
|
|
|
const { statusIds, isLoading, me } = this.props;
|
2016-10-25 02:11:02 +11:00
|
|
|
|
|
|
|
if (!statusIds) {
|
|
|
|
return <LoadingIndicator />;
|
|
|
|
}
|
2016-10-10 05:18:54 +11:00
|
|
|
|
2017-01-24 14:12:10 +11:00
|
|
|
return <StatusList statusIds={statusIds} isLoading={isLoading} me={me} onScrollToBottom={this.handleScrollToBottom} />
|
2016-10-10 05:18:54 +11:00
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
export default connect(mapStateToProps)(AccountTimeline);
|