2019-03-19 15:42:25 +00:00
|
|
|
// @flow
|
2017-09-13 12:17:14 +00:00
|
|
|
|
|
|
|
import React, { Component } from 'react';
|
|
|
|
import { connect } from 'react-redux';
|
|
|
|
|
|
|
|
import { LoadingIndicator } from '../../../base/react';
|
|
|
|
|
|
|
|
/**
|
2018-10-30 05:02:23 +00:00
|
|
|
* The type of the React {@code Component} props of
|
|
|
|
* {@link NetworkActivityIndicator}.
|
2017-09-13 12:17:14 +00:00
|
|
|
*/
|
2018-10-30 05:02:23 +00:00
|
|
|
type Props = {
|
|
|
|
|
2017-09-13 12:17:14 +00:00
|
|
|
/**
|
2018-10-30 05:02:23 +00:00
|
|
|
* Indicates whether there is network activity i.e. ongoing network
|
|
|
|
* requests.
|
2017-09-13 12:17:14 +00:00
|
|
|
*/
|
2018-10-30 05:02:23 +00:00
|
|
|
_networkActivity: boolean
|
|
|
|
};
|
2017-09-13 12:17:14 +00:00
|
|
|
|
2018-10-30 05:02:23 +00:00
|
|
|
/**
|
|
|
|
* The React {@code Component} which renders a progress indicator when there
|
|
|
|
* are ongoing network requests.
|
|
|
|
*/
|
|
|
|
class NetworkActivityIndicator extends Component<Props> {
|
2017-09-13 12:17:14 +00:00
|
|
|
/**
|
|
|
|
* 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)
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2019-03-19 15:42:25 +00:00
|
|
|
// $FlowExpectedError
|
2017-09-13 12:17:14 +00:00
|
|
|
export default connect(_mapStateToProps)(NetworkActivityIndicator);
|