2017-09-13 12:17:14 +00:00
|
|
|
/* @flow */
|
|
|
|
|
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
import React, { Component } from 'react';
|
|
|
|
import { connect } from 'react-redux';
|
|
|
|
|
|
|
|
import { LoadingIndicator } from '../../../base/react';
|
|
|
|
|
|
|
|
/**
|
2017-10-01 06:35:19 +00:00
|
|
|
* The React {@code Component} which renders a progress indicator when there
|
2017-09-13 12:17:14 +00:00
|
|
|
* are ongoing network requests.
|
|
|
|
*/
|
2017-10-24 22:26:56 +00:00
|
|
|
class NetworkActivityIndicator extends Component<*> {
|
2017-09-13 12:17:14 +00:00
|
|
|
/**
|
2017-10-01 06:35:19 +00:00
|
|
|
* {@code NetworkActivityIndicator} React {@code Component}'s prop types.
|
2017-09-13 12:17:14 +00:00
|
|
|
*
|
|
|
|
* @static
|
|
|
|
*/
|
|
|
|
static propTypes = {
|
|
|
|
/**
|
|
|
|
* Indicates whether there is network activity i.e. ongoing network
|
|
|
|
* requests.
|
|
|
|
*
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
_networkActivity: PropTypes.bool
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Implements React's {@link Component#render()}.
|
|
|
|
*
|
|
|
|
* @inheritdoc
|
|
|
|
* @returns {ReactElement}
|
|
|
|
*/
|
|
|
|
render() {
|
|
|
|
return this.props._networkActivity ? <LoadingIndicator /> : null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2017-10-01 06:35:19 +00:00
|
|
|
* Maps (parts of) the redux state to the React {@code Component} props of
|
|
|
|
* {@code NetworkActivityIndicator}.
|
2017-09-13 12:17:14 +00:00
|
|
|
*
|
|
|
|
* @param {Object} state - The redux state.
|
|
|
|
* @private
|
|
|
|
* @returns {{
|
|
|
|
* _networkActivity: boolean
|
|
|
|
* }}
|
|
|
|
*/
|
|
|
|
function _mapStateToProps(state) {
|
|
|
|
const { requests } = state['features/network-activity'];
|
|
|
|
|
|
|
|
return {
|
|
|
|
_networkActivity: Boolean(requests && requests.size)
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
export default connect(_mapStateToProps)(NetworkActivityIndicator);
|