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.

73 lines
2.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. const messages = defineMessages({
  15. heading: { id: 'column.follow_requests', defaultMessage: 'Follow requests' },
  16. });
  17. const mapStateToProps = state => ({
  18. accountIds: state.getIn(['user_lists', 'follow_requests', 'items']),
  19. });
  20. export default @connect(mapStateToProps)
  21. @injectIntl
  22. class FollowRequests extends ImmutablePureComponent {
  23. static propTypes = {
  24. params: PropTypes.object.isRequired,
  25. dispatch: PropTypes.func.isRequired,
  26. shouldUpdateScroll: PropTypes.func,
  27. accountIds: ImmutablePropTypes.list,
  28. intl: PropTypes.object.isRequired,
  29. };
  30. componentWillMount () {
  31. this.props.dispatch(fetchFollowRequests());
  32. }
  33. handleLoadMore = debounce(() => {
  34. this.props.dispatch(expandFollowRequests());
  35. }, 300, { leading: true });
  36. render () {
  37. const { intl, shouldUpdateScroll, accountIds } = this.props;
  38. if (!accountIds) {
  39. return (
  40. <Column>
  41. <LoadingIndicator />
  42. </Column>
  43. );
  44. }
  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. return (
  47. <Column icon='users' heading={intl.formatMessage(messages.heading)}>
  48. <ColumnBackButtonSlim />
  49. <ScrollableList
  50. scrollKey='follow_requests'
  51. onLoadMore={this.handleLoadMore}
  52. shouldUpdateScroll={shouldUpdateScroll}
  53. emptyMessage={emptyMessage}
  54. >
  55. {accountIds.map(id =>
  56. <AccountAuthorizeContainer key={id} id={id} />
  57. )}
  58. </ScrollableList>
  59. </Column>
  60. );
  61. }
  62. }