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.

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