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.

76 lines
2.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 LoadingIndicator from 'flavours/glitch/components/loading_indicator';
  6. import { ScrollContainer } from 'react-router-scroll-4';
  7. import Column from 'flavours/glitch/features/ui/components/column';
  8. import ColumnBackButtonSlim from 'flavours/glitch/components/column_back_button_slim';
  9. import AccountAuthorizeContainer from './containers/account_authorize_container';
  10. import { fetchFollowRequests, expandFollowRequests } from 'flavours/glitch/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. @connect(mapStateToProps)
  20. @injectIntl
  21. export default class FollowRequests extends ImmutablePureComponent {
  22. static propTypes = {
  23. params: PropTypes.object.isRequired,
  24. dispatch: PropTypes.func.isRequired,
  25. accountIds: ImmutablePropTypes.list,
  26. intl: PropTypes.object.isRequired,
  27. };
  28. componentWillMount () {
  29. this.props.dispatch(fetchFollowRequests());
  30. }
  31. handleScroll = (e) => {
  32. const { scrollTop, scrollHeight, clientHeight } = e.target;
  33. if (scrollTop === scrollHeight - clientHeight) {
  34. this.props.dispatch(expandFollowRequests());
  35. }
  36. }
  37. shouldUpdateScroll = (prevRouterProps, { location }) => {
  38. if ((((prevRouterProps || {}).location || {}).state || {}).mastodonModalOpen) return false;
  39. return !(location.state && location.state.mastodonModalOpen);
  40. }
  41. render () {
  42. const { intl, accountIds } = this.props;
  43. if (!accountIds) {
  44. return (
  45. <Column name='follow-requests'>
  46. <LoadingIndicator />
  47. </Column>
  48. );
  49. }
  50. return (
  51. <Column name='follow-requests' icon='users' heading={intl.formatMessage(messages.heading)}>
  52. <ColumnBackButtonSlim />
  53. <ScrollContainer scrollKey='follow_requests' shouldUpdateScroll={this.shouldUpdateScroll}>
  54. <div className='scrollable' onScroll={this.handleScroll}>
  55. {accountIds.map(id =>
  56. <AccountAuthorizeContainer key={id} id={id} />
  57. )}
  58. </div>
  59. </ScrollContainer>
  60. </Column>
  61. );
  62. }
  63. }