闭社主体 forked from https://github.com/tootsuite/mastodon
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.

52 lines
1.5 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)]),
  12. me: state.getIn(['meta', 'me'])
  13. });
  14. const AccountTimeline = React.createClass({
  15. propTypes: {
  16. params: React.PropTypes.object.isRequired,
  17. dispatch: React.PropTypes.func.isRequired,
  18. statusIds: ImmutablePropTypes.list
  19. },
  20. mixins: [PureRenderMixin],
  21. componentWillMount () {
  22. this.props.dispatch(fetchAccountTimeline(Number(this.props.params.accountId)));
  23. },
  24. componentWillReceiveProps(nextProps) {
  25. if (nextProps.params.accountId !== this.props.params.accountId && nextProps.params.accountId) {
  26. this.props.dispatch(fetchAccountTimeline(Number(nextProps.params.accountId)));
  27. }
  28. },
  29. handleScrollToBottom () {
  30. this.props.dispatch(expandAccountTimeline(Number(this.props.params.accountId)));
  31. },
  32. render () {
  33. const { statusIds, me } = this.props;
  34. if (!statusIds) {
  35. return <LoadingIndicator />;
  36. }
  37. return <StatusList statusIds={statusIds} me={me} onScrollToBottom={this.handleScrollToBottom} />
  38. }
  39. });
  40. export default connect(mapStateToProps)(AccountTimeline);