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.
 
 
 
 

90 lines
3.2 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, refreshAccountFeaturedTimeline, 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 { List as ImmutableList } from 'immutable';
  13. import ImmutablePureComponent from 'react-immutable-pure-component';
  14. const mapStateToProps = (state, { params: { accountId }, withReplies = false }) => {
  15. const path = withReplies ? `${accountId}:with_replies` : accountId;
  16. return {
  17. statusIds: state.getIn(['timelines', `account:${path}`, 'items'], ImmutableList()),
  18. featuredStatusIds: state.getIn(['timelines', `account:${accountId}:pinned`, 'items'], ImmutableList()),
  19. isLoading: state.getIn(['timelines', `account:${path}`, 'isLoading']),
  20. hasMore: !!state.getIn(['timelines', `account:${path}`, 'next']),
  21. };
  22. };
  23. @connect(mapStateToProps)
  24. export default class AccountTimeline extends ImmutablePureComponent {
  25. static propTypes = {
  26. params: PropTypes.object.isRequired,
  27. dispatch: PropTypes.func.isRequired,
  28. statusIds: ImmutablePropTypes.list,
  29. featuredStatusIds: ImmutablePropTypes.list,
  30. isLoading: PropTypes.bool,
  31. hasMore: PropTypes.bool,
  32. withReplies: PropTypes.bool,
  33. };
  34. componentWillMount () {
  35. const { params: { accountId }, withReplies } = this.props;
  36. this.props.dispatch(fetchAccount(accountId));
  37. this.props.dispatch(refreshAccountFeaturedTimeline(accountId));
  38. this.props.dispatch(refreshAccountTimeline(accountId, withReplies));
  39. }
  40. componentWillReceiveProps (nextProps) {
  41. if ((nextProps.params.accountId !== this.props.params.accountId && nextProps.params.accountId) || nextProps.withReplies !== this.props.withReplies) {
  42. this.props.dispatch(fetchAccount(nextProps.params.accountId));
  43. this.props.dispatch(refreshAccountFeaturedTimeline(nextProps.params.accountId));
  44. this.props.dispatch(refreshAccountTimeline(nextProps.params.accountId, nextProps.params.withReplies));
  45. }
  46. }
  47. handleScrollToBottom = () => {
  48. if (!this.props.isLoading && this.props.hasMore) {
  49. this.props.dispatch(expandAccountTimeline(this.props.params.accountId, this.props.withReplies));
  50. }
  51. }
  52. render () {
  53. const { statusIds, featuredStatusIds, isLoading, hasMore } = this.props;
  54. if (!statusIds && isLoading) {
  55. return (
  56. <Column>
  57. <LoadingIndicator />
  58. </Column>
  59. );
  60. }
  61. return (
  62. <Column>
  63. <ColumnBackButton />
  64. <StatusList
  65. prepend={<HeaderContainer accountId={this.props.params.accountId} />}
  66. scrollKey='account_timeline'
  67. statusIds={statusIds}
  68. featuredStatusIds={featuredStatusIds}
  69. isLoading={isLoading}
  70. hasMore={hasMore}
  71. onScrollToBottom={this.handleScrollToBottom}
  72. />
  73. </Column>
  74. );
  75. }
  76. }