index.js 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. import React from 'react';
  2. import { connect } from 'react-redux';
  3. import { defineMessages, injectIntl, FormattedMessage } from 'react-intl';
  4. import ImmutablePureComponent from 'react-immutable-pure-component';
  5. import PropTypes from 'prop-types';
  6. import ImmutablePropTypes from 'react-immutable-proptypes';
  7. import { debounce } from 'lodash';
  8. import LoadingIndicator from '../../components/loading_indicator';
  9. import Column from '../ui/components/column';
  10. import ColumnBackButtonSlim from '../../components/column_back_button_slim';
  11. import AccountAuthorizeContainer from './containers/account_authorize_container';
  12. import { fetchFollowRequests, expandFollowRequests } from '../../actions/accounts';
  13. import ScrollableList from '../../components/scrollable_list';
  14. import { me } from '../../initial_state';
  15. import { Helmet } from 'react-helmet';
  16. const messages = defineMessages({
  17. heading: { id: 'column.follow_requests', defaultMessage: 'Follow requests' },
  18. });
  19. const mapStateToProps = state => ({
  20. accountIds: state.getIn(['user_lists', 'follow_requests', 'items']),
  21. isLoading: state.getIn(['user_lists', 'follow_requests', 'isLoading'], true),
  22. hasMore: !!state.getIn(['user_lists', 'follow_requests', 'next']),
  23. locked: !!state.getIn(['accounts', me, 'locked']),
  24. domain: state.getIn(['meta', 'domain']),
  25. });
  26. export default @connect(mapStateToProps)
  27. @injectIntl
  28. class FollowRequests extends ImmutablePureComponent {
  29. static propTypes = {
  30. params: PropTypes.object.isRequired,
  31. dispatch: PropTypes.func.isRequired,
  32. hasMore: PropTypes.bool,
  33. isLoading: PropTypes.bool,
  34. accountIds: ImmutablePropTypes.list,
  35. locked: PropTypes.bool,
  36. domain: PropTypes.string,
  37. intl: PropTypes.object.isRequired,
  38. multiColumn: PropTypes.bool,
  39. };
  40. componentWillMount () {
  41. this.props.dispatch(fetchFollowRequests());
  42. }
  43. handleLoadMore = debounce(() => {
  44. this.props.dispatch(expandFollowRequests());
  45. }, 300, { leading: true });
  46. render () {
  47. const { intl, accountIds, hasMore, multiColumn, locked, domain, isLoading } = this.props;
  48. if (!accountIds) {
  49. return (
  50. <Column>
  51. <LoadingIndicator />
  52. </Column>
  53. );
  54. }
  55. const emptyMessage = <FormattedMessage id='empty_column.follow_requests' defaultMessage="You don't have any follow requests yet. When you receive one, it will show up here." />;
  56. const unlockedPrependMessage = locked ? null : (
  57. <div className='follow_requests-unlocked_explanation'>
  58. <FormattedMessage
  59. id='follow_requests.unlocked_explanation'
  60. defaultMessage='Even though your account is not locked, the {domain} staff thought you might want to review follow requests from these accounts manually.'
  61. values={{ domain: domain }}
  62. />
  63. </div>
  64. );
  65. return (
  66. <Column bindToDocument={!multiColumn} icon='user-plus' heading={intl.formatMessage(messages.heading)}>
  67. <ColumnBackButtonSlim />
  68. <ScrollableList
  69. scrollKey='follow_requests'
  70. onLoadMore={this.handleLoadMore}
  71. hasMore={hasMore}
  72. isLoading={isLoading}
  73. emptyMessage={emptyMessage}
  74. bindToDocument={!multiColumn}
  75. prepend={unlockedPrependMessage}
  76. >
  77. {accountIds.map(id =>
  78. <AccountAuthorizeContainer key={id} id={id} />,
  79. )}
  80. </ScrollableList>
  81. <Helmet>
  82. <meta name='robots' content='noindex' />
  83. </Helmet>
  84. </Column>
  85. );
  86. }
  87. }