Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

NetworkActivityIndicator.js 1.4KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. /* @flow */
  2. import PropTypes from 'prop-types';
  3. import React, { Component } from 'react';
  4. import { connect } from 'react-redux';
  5. import { LoadingIndicator } from '../../../base/react';
  6. /**
  7. * The React {@code Component} which renders a progress indicator when there
  8. * are ongoing network requests.
  9. */
  10. class NetworkActivityIndicator extends Component<*> {
  11. /**
  12. * {@code NetworkActivityIndicator} React {@code Component}'s prop types.
  13. *
  14. * @static
  15. */
  16. static propTypes = {
  17. /**
  18. * Indicates whether there is network activity i.e. ongoing network
  19. * requests.
  20. *
  21. * @private
  22. */
  23. _networkActivity: PropTypes.bool
  24. };
  25. /**
  26. * Implements React's {@link Component#render()}.
  27. *
  28. * @inheritdoc
  29. * @returns {ReactElement}
  30. */
  31. render() {
  32. return this.props._networkActivity ? <LoadingIndicator /> : null;
  33. }
  34. }
  35. /**
  36. * Maps (parts of) the redux state to the React {@code Component} props of
  37. * {@code NetworkActivityIndicator}.
  38. *
  39. * @param {Object} state - The redux state.
  40. * @private
  41. * @returns {{
  42. * _networkActivity: boolean
  43. * }}
  44. */
  45. function _mapStateToProps(state) {
  46. const { requests } = state['features/network-activity'];
  47. return {
  48. _networkActivity: Boolean(requests && requests.size)
  49. };
  50. }
  51. export default connect(_mapStateToProps)(NetworkActivityIndicator);