The code powering m.abunchtell.com https://m.abunchtell.com
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.
 
 
 
 

97 rader
3.5 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 { expandAccountFeaturedTimeline, 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. import { FormattedMessage } from 'react-intl';
  15. const mapStateToProps = (state, { params: { accountId }, withReplies = false }) => {
  16. const path = withReplies ? `${accountId}:with_replies` : accountId;
  17. return {
  18. statusIds: state.getIn(['timelines', `account:${path}`, 'items'], ImmutableList()),
  19. featuredStatusIds: withReplies ? ImmutableList() : state.getIn(['timelines', `account:${accountId}:pinned`, 'items'], ImmutableList()),
  20. isLoading: state.getIn(['timelines', `account:${path}`, 'isLoading']),
  21. hasMore: state.getIn(['timelines', `account:${path}`, 'hasMore']),
  22. };
  23. };
  24. export default @connect(mapStateToProps)
  25. class AccountTimeline extends ImmutablePureComponent {
  26. static propTypes = {
  27. params: PropTypes.object.isRequired,
  28. dispatch: PropTypes.func.isRequired,
  29. shouldUpdateScroll: PropTypes.func,
  30. statusIds: ImmutablePropTypes.list,
  31. featuredStatusIds: ImmutablePropTypes.list,
  32. isLoading: PropTypes.bool,
  33. hasMore: PropTypes.bool,
  34. withReplies: PropTypes.bool,
  35. };
  36. componentWillMount () {
  37. const { params: { accountId }, withReplies } = this.props;
  38. this.props.dispatch(fetchAccount(accountId));
  39. if (!withReplies) {
  40. this.props.dispatch(expandAccountFeaturedTimeline(accountId));
  41. }
  42. this.props.dispatch(expandAccountTimeline(accountId, { withReplies }));
  43. }
  44. componentWillReceiveProps (nextProps) {
  45. if ((nextProps.params.accountId !== this.props.params.accountId && nextProps.params.accountId) || nextProps.withReplies !== this.props.withReplies) {
  46. this.props.dispatch(fetchAccount(nextProps.params.accountId));
  47. if (!nextProps.withReplies) {
  48. this.props.dispatch(expandAccountFeaturedTimeline(nextProps.params.accountId));
  49. }
  50. this.props.dispatch(expandAccountTimeline(nextProps.params.accountId, { withReplies: nextProps.params.withReplies }));
  51. }
  52. }
  53. handleLoadMore = maxId => {
  54. this.props.dispatch(expandAccountTimeline(this.props.params.accountId, { maxId, withReplies: this.props.withReplies }));
  55. }
  56. render () {
  57. const { shouldUpdateScroll, statusIds, featuredStatusIds, isLoading, hasMore } = this.props;
  58. if (!statusIds && isLoading) {
  59. return (
  60. <Column>
  61. <LoadingIndicator />
  62. </Column>
  63. );
  64. }
  65. return (
  66. <Column>
  67. <ColumnBackButton />
  68. <StatusList
  69. prepend={<HeaderContainer accountId={this.props.params.accountId} />}
  70. alwaysPrepend
  71. scrollKey='account_timeline'
  72. statusIds={statusIds}
  73. featuredStatusIds={featuredStatusIds}
  74. isLoading={isLoading}
  75. hasMore={hasMore}
  76. onLoadMore={this.handleLoadMore}
  77. shouldUpdateScroll={shouldUpdateScroll}
  78. emptyMessage={<FormattedMessage id='empty_column.account_timeline' defaultMessage='No toots here!' />}
  79. />
  80. </Column>
  81. );
  82. }
  83. }