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.

92 lines
3.4 KiB

  1. import React from 'react';
  2. import { connect } from 'react-redux';
  3. import PropTypes from 'prop-types';
  4. import ImmutablePropTypes from 'react-immutable-proptypes';
  5. import { debounce } from 'lodash';
  6. import Column from 'flavours/glitch/features/ui/components/column';
  7. import ColumnBackButtonSlim from 'flavours/glitch/components/column_back_button_slim';
  8. import AccountAuthorizeContainer from './containers/account_authorize_container';
  9. import { fetchFollowRequests, expandFollowRequests } from 'flavours/glitch/actions/accounts';
  10. import { defineMessages, injectIntl, FormattedMessage } from 'react-intl';
  11. import ImmutablePureComponent from 'react-immutable-pure-component';
  12. import ScrollableList from 'flavours/glitch/components/scrollable_list';
  13. import { me } from 'flavours/glitch/initial_state';
  14. import { Helmet } from 'react-helmet';
  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. class FollowRequests extends ImmutablePureComponent {
  26. static propTypes = {
  27. params: PropTypes.object.isRequired,
  28. dispatch: PropTypes.func.isRequired,
  29. hasMore: PropTypes.bool,
  30. isLoading: PropTypes.bool,
  31. accountIds: ImmutablePropTypes.list,
  32. locked: PropTypes.bool,
  33. domain: PropTypes.string,
  34. intl: PropTypes.object.isRequired,
  35. multiColumn: PropTypes.bool,
  36. };
  37. componentWillMount () {
  38. this.props.dispatch(fetchFollowRequests());
  39. }
  40. handleLoadMore = debounce(() => {
  41. this.props.dispatch(expandFollowRequests());
  42. }, 300, { leading: true });
  43. render () {
  44. const { intl, accountIds, hasMore, multiColumn, locked, domain, isLoading } = this.props;
  45. 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." />;
  46. const unlockedPrependMessage = !locked && accountIds.size > 0 && (
  47. <div className='follow_requests-unlocked_explanation'>
  48. <FormattedMessage
  49. id='follow_requests.unlocked_explanation'
  50. defaultMessage='Even though your account is not locked, the {domain} staff thought you might want to review follow requests from these accounts manually.'
  51. values={{ domain: domain }}
  52. />
  53. </div>
  54. );
  55. return (
  56. <Column bindToDocument={!multiColumn} name='follow-requests' icon='user-plus' heading={intl.formatMessage(messages.heading)}>
  57. <ColumnBackButtonSlim />
  58. <ScrollableList
  59. scrollKey='follow_requests'
  60. onLoadMore={this.handleLoadMore}
  61. hasMore={hasMore}
  62. isLoading={isLoading}
  63. showLoading={isLoading && accountIds.size === 0}
  64. emptyMessage={emptyMessage}
  65. bindToDocument={!multiColumn}
  66. prepend={unlockedPrependMessage}
  67. >
  68. {accountIds.map(id =>
  69. <AccountAuthorizeContainer key={id} id={id} />,
  70. )}
  71. </ScrollableList>
  72. <Helmet>
  73. <meta name='robots' content='noindex' />
  74. </Helmet>
  75. </Column>
  76. );
  77. }
  78. }
  79. export default connect(mapStateToProps)(injectIntl(FollowRequests));