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.

94 lines
3.3 KiB

  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. const messages = defineMessages({
  16. heading: { id: 'column.follow_requests', defaultMessage: 'Follow requests' },
  17. });
  18. const mapStateToProps = state => ({
  19. accountIds: state.getIn(['user_lists', 'follow_requests', 'items']),
  20. isLoading: state.getIn(['user_lists', 'follow_requests', 'isLoading'], true),
  21. hasMore: !!state.getIn(['user_lists', 'follow_requests', 'next']),
  22. locked: !!state.getIn(['accounts', me, 'locked']),
  23. domain: state.getIn(['meta', 'domain']),
  24. });
  25. export default @connect(mapStateToProps)
  26. @injectIntl
  27. class FollowRequests extends ImmutablePureComponent {
  28. static propTypes = {
  29. params: PropTypes.object.isRequired,
  30. dispatch: PropTypes.func.isRequired,
  31. hasMore: PropTypes.bool,
  32. isLoading: PropTypes.bool,
  33. accountIds: ImmutablePropTypes.list,
  34. locked: PropTypes.bool,
  35. domain: PropTypes.string,
  36. intl: PropTypes.object.isRequired,
  37. multiColumn: PropTypes.bool,
  38. };
  39. componentWillMount () {
  40. this.props.dispatch(fetchFollowRequests());
  41. }
  42. handleLoadMore = debounce(() => {
  43. this.props.dispatch(expandFollowRequests());
  44. }, 300, { leading: true });
  45. render () {
  46. const { intl, accountIds, hasMore, multiColumn, locked, domain, isLoading } = this.props;
  47. if (!accountIds) {
  48. return (
  49. <Column>
  50. <LoadingIndicator />
  51. </Column>
  52. );
  53. }
  54. 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." />;
  55. const unlockedPrependMessage = locked ? null : (
  56. <div className='follow_requests-unlocked_explanation'>
  57. <FormattedMessage
  58. id='follow_requests.unlocked_explanation'
  59. defaultMessage='Even though your account is not locked, the {domain} staff thought you might want to review follow requests from these accounts manually.'
  60. values={{ domain: domain }}
  61. />
  62. </div>
  63. );
  64. return (
  65. <Column bindToDocument={!multiColumn} icon='user-plus' heading={intl.formatMessage(messages.heading)}>
  66. <ColumnBackButtonSlim />
  67. <ScrollableList
  68. scrollKey='follow_requests'
  69. onLoadMore={this.handleLoadMore}
  70. hasMore={hasMore}
  71. isLoading={isLoading}
  72. emptyMessage={emptyMessage}
  73. bindToDocument={!multiColumn}
  74. prepend={unlockedPrependMessage}
  75. >
  76. {accountIds.map(id =>
  77. <AccountAuthorizeContainer key={id} id={id} />,
  78. )}
  79. </ScrollableList>
  80. </Column>
  81. );
  82. }
  83. }