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.

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