2016-11-16 16:20:52 +00:00
|
|
|
import { connect } from 'react-redux';
|
|
|
|
import PureRenderMixin from 'react-addons-pure-render-mixin';
|
|
|
|
import ImmutablePropTypes from 'react-immutable-proptypes';
|
2016-10-09 18:18:54 +00:00
|
|
|
import {
|
2017-01-30 21:35:36 +00:00
|
|
|
fetchAccount,
|
2016-10-09 18:18:54 +00:00
|
|
|
fetchAccountTimeline,
|
|
|
|
expandAccountTimeline
|
2016-11-16 16:20:52 +00:00
|
|
|
} from '../../actions/accounts';
|
|
|
|
import StatusList from '../../components/status_list';
|
|
|
|
import LoadingIndicator from '../../components/loading_indicator';
|
2017-01-30 20:40:55 +00:00
|
|
|
import Column from '../ui/components/column';
|
|
|
|
import HeaderContainer from './containers/header_container';
|
|
|
|
import ColumnBackButton from '../../components/column_back_button';
|
2017-01-31 21:34:33 +00:00
|
|
|
import Immutable from 'immutable';
|
2016-10-09 18:18:54 +00:00
|
|
|
|
|
|
|
const mapStateToProps = (state, props) => ({
|
2017-01-31 21:34:33 +00:00
|
|
|
statusIds: state.getIn(['timelines', 'accounts_timelines', Number(props.params.accountId), 'items'], Immutable.List()),
|
2017-01-24 03:12:10 +00:00
|
|
|
isLoading: state.getIn(['timelines', 'accounts_timelines', Number(props.params.accountId), 'isLoading']),
|
2017-02-22 15:30:09 +00:00
|
|
|
hasMore: !!state.getIn(['timelines', 'accounts_timelines', Number(props.params.accountId), 'next']),
|
2016-10-30 14:06:43 +00:00
|
|
|
me: state.getIn(['meta', 'me'])
|
2016-10-09 18:18:54 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
const AccountTimeline = React.createClass({
|
|
|
|
|
|
|
|
propTypes: {
|
|
|
|
params: React.PropTypes.object.isRequired,
|
|
|
|
dispatch: React.PropTypes.func.isRequired,
|
2017-01-16 12:27:58 +00:00
|
|
|
statusIds: ImmutablePropTypes.list,
|
2017-01-24 03:12:10 +00:00
|
|
|
isLoading: React.PropTypes.bool,
|
2017-02-22 15:30:09 +00:00
|
|
|
hasMore: React.PropTypes.bool,
|
2017-01-16 12:27:58 +00:00
|
|
|
me: React.PropTypes.number.isRequired
|
2016-10-09 18:18:54 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
mixins: [PureRenderMixin],
|
|
|
|
|
|
|
|
componentWillMount () {
|
2017-01-30 21:35:36 +00:00
|
|
|
this.props.dispatch(fetchAccount(Number(this.props.params.accountId)));
|
2016-10-09 18:18:54 +00:00
|
|
|
this.props.dispatch(fetchAccountTimeline(Number(this.props.params.accountId)));
|
|
|
|
},
|
|
|
|
|
|
|
|
componentWillReceiveProps(nextProps) {
|
|
|
|
if (nextProps.params.accountId !== this.props.params.accountId && nextProps.params.accountId) {
|
2017-01-30 21:35:36 +00:00
|
|
|
this.props.dispatch(fetchAccount(Number(nextProps.params.accountId)));
|
2016-10-09 18:18:54 +00:00
|
|
|
this.props.dispatch(fetchAccountTimeline(Number(nextProps.params.accountId)));
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
handleScrollToBottom () {
|
2016-10-16 23:23:41 +00:00
|
|
|
this.props.dispatch(expandAccountTimeline(Number(this.props.params.accountId)));
|
2016-10-09 18:18:54 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
render () {
|
2017-02-22 15:30:09 +00:00
|
|
|
const { statusIds, isLoading, hasMore, me } = this.props;
|
2016-10-24 15:11:02 +00:00
|
|
|
|
2017-01-31 21:34:33 +00:00
|
|
|
if (!statusIds && isLoading) {
|
2017-01-30 20:40:55 +00:00
|
|
|
return (
|
|
|
|
<Column>
|
|
|
|
<LoadingIndicator />
|
|
|
|
</Column>
|
|
|
|
);
|
2016-10-24 15:11:02 +00:00
|
|
|
}
|
2016-10-09 18:18:54 +00:00
|
|
|
|
2017-01-30 20:40:55 +00:00
|
|
|
return (
|
|
|
|
<Column>
|
|
|
|
<ColumnBackButton />
|
|
|
|
|
|
|
|
<StatusList
|
|
|
|
prepend={<HeaderContainer accountId={this.props.params.accountId} />}
|
|
|
|
statusIds={statusIds}
|
|
|
|
isLoading={isLoading}
|
2017-02-22 15:30:09 +00:00
|
|
|
hasMore={hasMore}
|
2017-01-30 20:40:55 +00:00
|
|
|
me={me}
|
|
|
|
onScrollToBottom={this.handleScrollToBottom}
|
|
|
|
/>
|
|
|
|
</Column>
|
|
|
|
);
|
2016-10-09 18:18:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
export default connect(mapStateToProps)(AccountTimeline);
|