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.

75 lines
2.3 KiB

  1. import React from 'react';
  2. import { connect } from 'react-redux';
  3. import ImmutablePropTypes from 'react-immutable-proptypes';
  4. import PropTypes from 'prop-types';
  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 AccountContainer from 'flavours/glitch/containers/account_container';
  10. import { fetchBlocks, expandBlocks } from 'flavours/glitch/actions/blocks';
  11. import { defineMessages, injectIntl } from 'react-intl';
  12. import ImmutablePureComponent from 'react-immutable-pure-component';
  13. const messages = defineMessages({
  14. heading: { id: 'column.blocks', defaultMessage: 'Blocked users' },
  15. });
  16. const mapStateToProps = state => ({
  17. accountIds: state.getIn(['user_lists', 'blocks', 'items']),
  18. });
  19. @connect(mapStateToProps)
  20. @injectIntl
  21. export default class Blocks 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(fetchBlocks());
  30. }
  31. handleScroll = (e) => {
  32. const { scrollTop, scrollHeight, clientHeight } = e.target;
  33. if (scrollTop === scrollHeight - clientHeight) {
  34. this.props.dispatch(expandBlocks());
  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>
  46. <LoadingIndicator />
  47. </Column>
  48. );
  49. }
  50. return (
  51. <Column name='blocks' icon='ban' heading={intl.formatMessage(messages.heading)}>
  52. <ColumnBackButtonSlim />
  53. <ScrollContainer scrollKey='blocks' shouldUpdateScroll={this.shouldUpdateScroll}>
  54. <div className='scrollable' onScroll={this.handleScroll}>
  55. {accountIds.map(id =>
  56. <AccountContainer key={id} id={id} />
  57. )}
  58. </div>
  59. </ScrollContainer>
  60. </Column>
  61. );
  62. }
  63. }