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.

NetworkActivityIndicator.js 1.3KB

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