You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

55 lines
1.7 KiB

  1. import { connect } from 'react-redux';
  2. import PureRenderMixin from 'react-addons-pure-render-mixin';
  3. import ImmutablePropTypes from 'react-immutable-proptypes';
  4. import {
  5. fetchAccountTimeline,
  6. expandAccountTimeline
  7. } from '../../actions/accounts';
  8. import StatusList from '../../components/status_list';
  9. import LoadingIndicator from '../../components/loading_indicator';
  10. const mapStateToProps = (state, props) => ({
  11. statusIds: state.getIn(['timelines', 'accounts_timelines', Number(props.params.accountId), 'items']),
  12. isLoading: state.getIn(['timelines', 'accounts_timelines', Number(props.params.accountId), 'isLoading']),
  13. me: state.getIn(['meta', 'me'])
  14. });
  15. const AccountTimeline = React.createClass({
  16. propTypes: {
  17. params: React.PropTypes.object.isRequired,
  18. dispatch: React.PropTypes.func.isRequired,
  19. statusIds: ImmutablePropTypes.list,
  20. isLoading: React.PropTypes.bool,
  21. me: React.PropTypes.number.isRequired
  22. },
  23. mixins: [PureRenderMixin],
  24. componentWillMount () {
  25. this.props.dispatch(fetchAccountTimeline(Number(this.props.params.accountId)));
  26. },
  27. componentWillReceiveProps(nextProps) {
  28. if (nextProps.params.accountId !== this.props.params.accountId && nextProps.params.accountId) {
  29. this.props.dispatch(fetchAccountTimeline(Number(nextProps.params.accountId)));
  30. }
  31. },
  32. handleScrollToBottom () {
  33. this.props.dispatch(expandAccountTimeline(Number(this.props.params.accountId)));
  34. },
  35. render () {
  36. const { statusIds, isLoading, me } = this.props;
  37. if (!statusIds) {
  38. return <LoadingIndicator />;
  39. }
  40. return <StatusList statusIds={statusIds} isLoading={isLoading} me={me} onScrollToBottom={this.handleScrollToBottom} />
  41. }
  42. });
  43. export default connect(mapStateToProps)(AccountTimeline);