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

80 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. @connect(mapStateToProps)
  21. export default class AccountTimeline extends ImmutablePureComponent {
  22. static propTypes = {
  23. params: PropTypes.object.isRequired,
  24. dispatch: PropTypes.func.isRequired,
  25. statusIds: ImmutablePropTypes.list,
  26. isLoading: PropTypes.bool,
  27. hasMore: PropTypes.bool,
  28. me: PropTypes.number.isRequired,
  29. };
  30. componentWillMount () {
  31. this.props.dispatch(fetchAccount(Number(this.props.params.accountId)));
  32. this.props.dispatch(refreshAccountTimeline(Number(this.props.params.accountId)));
  33. }
  34. componentWillReceiveProps (nextProps) {
  35. if (nextProps.params.accountId !== this.props.params.accountId && nextProps.params.accountId) {
  36. this.props.dispatch(fetchAccount(Number(nextProps.params.accountId)));
  37. this.props.dispatch(refreshAccountTimeline(Number(nextProps.params.accountId)));
  38. }
  39. }
  40. handleScrollToBottom = () => {
  41. if (!this.props.isLoading && this.props.hasMore) {
  42. this.props.dispatch(expandAccountTimeline(Number(this.props.params.accountId)));
  43. }
  44. }
  45. render () {
  46. const { statusIds, isLoading, hasMore, me } = this.props;
  47. if (!statusIds && isLoading) {
  48. return (
  49. <Column>
  50. <LoadingIndicator />
  51. </Column>
  52. );
  53. }
  54. return (
  55. <Column>
  56. <ColumnBackButton />
  57. <StatusList
  58. prepend={<HeaderContainer accountId={this.props.params.accountId} />}
  59. scrollKey='account_timeline'
  60. statusIds={statusIds}
  61. isLoading={isLoading}
  62. hasMore={hasMore}
  63. me={me}
  64. onScrollToBottom={this.handleScrollToBottom}
  65. />
  66. </Column>
  67. );
  68. }
  69. }