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

  1. import React from 'react';
  2. import { connect } from 'react-redux';
  3. import ImmutablePropTypes from 'react-immutable-proptypes';
  4. import PropTypes from 'prop-types';
  5. import { fetchAccount } from '../../actions/accounts';
  6. import { refreshAccountTimeline, expandAccountTimeline } from '../../actions/timelines';
  7. import StatusList from '../../components/status_list';
  8. import LoadingIndicator from '../../components/loading_indicator';
  9. import Column from '../ui/components/column';
  10. import HeaderContainer from './containers/header_container';
  11. import ColumnBackButton from '../../components/column_back_button';
  12. import Immutable from 'immutable';
  13. import ImmutablePureComponent from 'react-immutable-pure-component';
  14. const mapStateToProps = (state, props) => ({
  15. statusIds: state.getIn(['timelines', `account:${Number(props.params.accountId)}`, 'items'], Immutable.List()),
  16. isLoading: state.getIn(['timelines', `account:${Number(props.params.accountId)}`, 'isLoading']),
  17. hasMore: !!state.getIn(['timelines', `account:${Number(props.params.accountId)}`, 'next']),
  18. me: state.getIn(['meta', 'me']),
  19. });
  20. class AccountTimeline extends ImmutablePureComponent {
  21. static propTypes = {
  22. params: PropTypes.object.isRequired,
  23. dispatch: PropTypes.func.isRequired,
  24. statusIds: ImmutablePropTypes.list,
  25. isLoading: PropTypes.bool,
  26. hasMore: PropTypes.bool,
  27. me: PropTypes.number.isRequired,
  28. };
  29. componentWillMount () {
  30. this.props.dispatch(fetchAccount(Number(this.props.params.accountId)));
  31. this.props.dispatch(refreshAccountTimeline(Number(this.props.params.accountId)));
  32. }
  33. componentWillReceiveProps (nextProps) {
  34. if (nextProps.params.accountId !== this.props.params.accountId && nextProps.params.accountId) {
  35. this.props.dispatch(fetchAccount(Number(nextProps.params.accountId)));
  36. this.props.dispatch(refreshAccountTimeline(Number(nextProps.params.accountId)));
  37. }
  38. }
  39. handleScrollToBottom = () => {
  40. if (!this.props.isLoading && this.props.hasMore) {
  41. this.props.dispatch(expandAccountTimeline(Number(this.props.params.accountId)));
  42. }
  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. scrollKey='account_timeline'
  59. statusIds={statusIds}
  60. isLoading={isLoading}
  61. hasMore={hasMore}
  62. me={me}
  63. onScrollToBottom={this.handleScrollToBottom}
  64. />
  65. </Column>
  66. );
  67. }
  68. }
  69. export default connect(mapStateToProps)(AccountTimeline);