闭社主体 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.

81 lines
2.6 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. fetchAccount,
  6. fetchAccountTimeline,
  7. expandAccountTimeline
  8. } from '../../actions/accounts';
  9. import StatusList from '../../components/status_list';
  10. import LoadingIndicator from '../../components/loading_indicator';
  11. import Column from '../ui/components/column';
  12. import HeaderContainer from './containers/header_container';
  13. import ColumnBackButton from '../../components/column_back_button';
  14. import Immutable from 'immutable';
  15. const mapStateToProps = (state, props) => ({
  16. statusIds: state.getIn(['timelines', 'accounts_timelines', Number(props.params.accountId), 'items'], Immutable.List()),
  17. isLoading: state.getIn(['timelines', 'accounts_timelines', Number(props.params.accountId), 'isLoading']),
  18. hasMore: !!state.getIn(['timelines', 'accounts_timelines', Number(props.params.accountId), 'next']),
  19. me: state.getIn(['meta', 'me'])
  20. });
  21. const AccountTimeline = React.createClass({
  22. propTypes: {
  23. params: React.PropTypes.object.isRequired,
  24. dispatch: React.PropTypes.func.isRequired,
  25. statusIds: ImmutablePropTypes.list,
  26. isLoading: React.PropTypes.bool,
  27. hasMore: React.PropTypes.bool,
  28. me: React.PropTypes.number.isRequired
  29. },
  30. mixins: [PureRenderMixin],
  31. componentWillMount () {
  32. this.props.dispatch(fetchAccount(Number(this.props.params.accountId)));
  33. this.props.dispatch(fetchAccountTimeline(Number(this.props.params.accountId)));
  34. },
  35. componentWillReceiveProps(nextProps) {
  36. if (nextProps.params.accountId !== this.props.params.accountId && nextProps.params.accountId) {
  37. this.props.dispatch(fetchAccount(Number(nextProps.params.accountId)));
  38. this.props.dispatch(fetchAccountTimeline(Number(nextProps.params.accountId)));
  39. }
  40. },
  41. handleScrollToBottom () {
  42. this.props.dispatch(expandAccountTimeline(Number(this.props.params.accountId)));
  43. },
  44. render () {
  45. const { statusIds, isLoading, hasMore, me } = this.props;
  46. if (!statusIds && isLoading) {
  47. return (
  48. <Column>
  49. <LoadingIndicator />
  50. </Column>
  51. );
  52. }
  53. return (
  54. <Column>
  55. <ColumnBackButton />
  56. <StatusList
  57. prepend={<HeaderContainer accountId={this.props.params.accountId} />}
  58. statusIds={statusIds}
  59. isLoading={isLoading}
  60. hasMore={hasMore}
  61. me={me}
  62. onScrollToBottom={this.handleScrollToBottom}
  63. />
  64. </Column>
  65. );
  66. }
  67. });
  68. export default connect(mapStateToProps)(AccountTimeline);