The code powering m.abunchtell.com https://m.abunchtell.com
25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.
 
 
 
 

125 satır
4.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. import { fetchAccountIdentityProofs } from '../../actions/identity_proofs';
  16. import MissingIndicator from 'mastodon/components/missing_indicator';
  17. const emptyList = ImmutableList();
  18. const mapStateToProps = (state, { params: { accountId }, withReplies = false }) => {
  19. const path = withReplies ? `${accountId}:with_replies` : accountId;
  20. return {
  21. isAccount: !!state.getIn(['accounts', accountId]),
  22. statusIds: state.getIn(['timelines', `account:${path}`, 'items'], emptyList),
  23. featuredStatusIds: withReplies ? ImmutableList() : state.getIn(['timelines', `account:${accountId}:pinned`, 'items'], emptyList),
  24. isLoading: state.getIn(['timelines', `account:${path}`, 'isLoading']),
  25. hasMore: state.getIn(['timelines', `account:${path}`, 'hasMore']),
  26. blockedBy: state.getIn(['relationships', accountId, 'blocked_by'], false),
  27. };
  28. };
  29. export default @connect(mapStateToProps)
  30. class AccountTimeline extends ImmutablePureComponent {
  31. static propTypes = {
  32. params: PropTypes.object.isRequired,
  33. dispatch: PropTypes.func.isRequired,
  34. shouldUpdateScroll: PropTypes.func,
  35. statusIds: ImmutablePropTypes.list,
  36. featuredStatusIds: ImmutablePropTypes.list,
  37. isLoading: PropTypes.bool,
  38. hasMore: PropTypes.bool,
  39. withReplies: PropTypes.bool,
  40. blockedBy: PropTypes.bool,
  41. isAccount: PropTypes.bool,
  42. multiColumn: PropTypes.bool,
  43. };
  44. componentWillMount () {
  45. const { params: { accountId }, withReplies } = this.props;
  46. this.props.dispatch(fetchAccount(accountId));
  47. this.props.dispatch(fetchAccountIdentityProofs(accountId));
  48. if (!withReplies) {
  49. this.props.dispatch(expandAccountFeaturedTimeline(accountId));
  50. }
  51. this.props.dispatch(expandAccountTimeline(accountId, { withReplies }));
  52. }
  53. componentWillReceiveProps (nextProps) {
  54. if ((nextProps.params.accountId !== this.props.params.accountId && nextProps.params.accountId) || nextProps.withReplies !== this.props.withReplies) {
  55. this.props.dispatch(fetchAccount(nextProps.params.accountId));
  56. this.props.dispatch(fetchAccountIdentityProofs(nextProps.params.accountId));
  57. if (!nextProps.withReplies) {
  58. this.props.dispatch(expandAccountFeaturedTimeline(nextProps.params.accountId));
  59. }
  60. this.props.dispatch(expandAccountTimeline(nextProps.params.accountId, { withReplies: nextProps.params.withReplies }));
  61. }
  62. }
  63. handleLoadMore = maxId => {
  64. this.props.dispatch(expandAccountTimeline(this.props.params.accountId, { maxId, withReplies: this.props.withReplies }));
  65. }
  66. render () {
  67. const { shouldUpdateScroll, statusIds, featuredStatusIds, isLoading, hasMore, blockedBy, isAccount, multiColumn } = this.props;
  68. if (!isAccount) {
  69. return (
  70. <Column>
  71. <ColumnBackButton multiColumn={multiColumn} />
  72. <MissingIndicator />
  73. </Column>
  74. );
  75. }
  76. if (!statusIds && isLoading) {
  77. return (
  78. <Column>
  79. <LoadingIndicator />
  80. </Column>
  81. );
  82. }
  83. const emptyMessage = blockedBy ? <FormattedMessage id='empty_column.account_unavailable' defaultMessage='Profile unavailable' /> : <FormattedMessage id='empty_column.account_timeline' defaultMessage='No toots here!' />;
  84. return (
  85. <Column>
  86. <ColumnBackButton multiColumn={multiColumn} />
  87. <StatusList
  88. prepend={<HeaderContainer accountId={this.props.params.accountId} />}
  89. alwaysPrepend
  90. scrollKey='account_timeline'
  91. statusIds={blockedBy ? emptyList : statusIds}
  92. featuredStatusIds={featuredStatusIds}
  93. isLoading={isLoading}
  94. hasMore={hasMore}
  95. onLoadMore={this.handleLoadMore}
  96. shouldUpdateScroll={shouldUpdateScroll}
  97. emptyMessage={emptyMessage}
  98. bindToDocument={!multiColumn}
  99. timelineId='account'
  100. />
  101. </Column>
  102. );
  103. }
  104. }