The code powering m.abunchtell.com https://m.abunchtell.com
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.
 
 
 
 

87 rivejä
2.7 KiB

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