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.

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