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.

71 lines
2.1 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 LoadingIndicator from '../../components/loading_indicator';
  6. import { ScrollContainer } from 'react-router-scroll';
  7. import Column from '../ui/components/column';
  8. import ColumnBackButtonSlim from '../../components/column_back_button_slim';
  9. import AccountAuthorizeContainer from './containers/account_authorize_container';
  10. import { fetchFollowRequests, expandFollowRequests } from '../../actions/accounts';
  11. import { defineMessages, injectIntl } from 'react-intl';
  12. import ImmutablePureComponent from 'react-immutable-pure-component';
  13. const messages = defineMessages({
  14. heading: { id: 'column.follow_requests', defaultMessage: 'Follow requests' },
  15. });
  16. const mapStateToProps = state => ({
  17. accountIds: state.getIn(['user_lists', 'follow_requests', 'items']),
  18. });
  19. class FollowRequests extends ImmutablePureComponent {
  20. static propTypes = {
  21. params: PropTypes.object.isRequired,
  22. dispatch: PropTypes.func.isRequired,
  23. accountIds: ImmutablePropTypes.list,
  24. intl: PropTypes.object.isRequired,
  25. };
  26. componentWillMount () {
  27. this.props.dispatch(fetchFollowRequests());
  28. }
  29. handleScroll = (e) => {
  30. const { scrollTop, scrollHeight, clientHeight } = e.target;
  31. if (scrollTop === scrollHeight - clientHeight) {
  32. this.props.dispatch(expandFollowRequests());
  33. }
  34. }
  35. render () {
  36. const { intl, accountIds } = this.props;
  37. if (!accountIds) {
  38. return (
  39. <Column>
  40. <LoadingIndicator />
  41. </Column>
  42. );
  43. }
  44. return (
  45. <Column icon='users' heading={intl.formatMessage(messages.heading)}>
  46. <ColumnBackButtonSlim />
  47. <ScrollContainer scrollKey='follow_requests'>
  48. <div className='scrollable' onScroll={this.handleScroll}>
  49. {accountIds.map(id =>
  50. <AccountAuthorizeContainer key={id} id={id} />
  51. )}
  52. </div>
  53. </ScrollContainer>
  54. </Column>
  55. );
  56. }
  57. }
  58. export default connect(mapStateToProps)(injectIntl(FollowRequests));