mirror of
https://github.com/Kong/insomnia
synced 2024-11-08 23:00:30 +00:00
549ce23ce8
* All projects into monorepo * Update CI * More CI updates * Extracted a bunch of things into packages * Publish - insomnia-plugin-base64@1.0.1 - insomnia-plugin-default-headers@1.0.2 - insomnia-plugin-file@1.0.1 - insomnia-plugin-hash@1.0.1 - insomnia-plugin-now@1.0.1 - insomnia-plugin-request@1.0.1 - insomnia-plugin-response@1.0.1 - insomnia-plugin-uuid@1.0.1 - insomnia-cookies@0.0.2 - insomnia-importers@1.5.2 - insomnia-prettify@0.0.3 - insomnia-url@0.0.2 - insomnia-xpath@0.0.2 * A bunch of small fixes * Improved build script * Fixed * Merge dangling files * Usability refactor * Handle duplicate plugin names
72 lines
1.8 KiB
JavaScript
72 lines
1.8 KiB
JavaScript
import React, {PureComponent} from 'react';
|
|
import PropTypes from 'prop-types';
|
|
import autobind from 'autobind-decorator';
|
|
import classnames from 'classnames';
|
|
import {REQUEST_TIME_TO_SHOW_COUNTER} from '../../common/constants';
|
|
|
|
@autobind
|
|
class ResponseTimer extends PureComponent {
|
|
constructor (props) {
|
|
super(props);
|
|
this._interval = null;
|
|
this.state = {
|
|
elapsedTime: 0
|
|
};
|
|
}
|
|
|
|
componentWillUnmount () {
|
|
clearInterval(this._interval);
|
|
}
|
|
|
|
_handleUpdateElapsedTime () {
|
|
const {loadStartTime} = this.props;
|
|
const millis = Date.now() - loadStartTime - 200;
|
|
const elapsedTime = millis / 1000;
|
|
this.setState({elapsedTime});
|
|
}
|
|
|
|
componentDidUpdate () {
|
|
const {loadStartTime} = this.props;
|
|
|
|
if (loadStartTime <= 0) {
|
|
clearInterval(this._interval);
|
|
return;
|
|
}
|
|
|
|
clearInterval(this._interval); // Just to be sure
|
|
this._interval = setInterval(this._handleUpdateElapsedTime, 100);
|
|
this._handleUpdateElapsedTime();
|
|
}
|
|
|
|
render () {
|
|
const {handleCancel, loadStartTime} = this.props;
|
|
const {elapsedTime} = this.state;
|
|
|
|
const show = loadStartTime > 0;
|
|
|
|
return (
|
|
<div className={classnames('overlay theme--overlay', {'overlay--hidden': !show})}>
|
|
{elapsedTime >= REQUEST_TIME_TO_SHOW_COUNTER
|
|
? <h2>{elapsedTime.toFixed(1)} seconds...</h2>
|
|
: <h2>Loading...</h2>
|
|
}
|
|
<div className="pad">
|
|
<i className="fa fa-refresh fa-spin"/>
|
|
</div>
|
|
<div className="pad">
|
|
<button className="btn btn--clicky" onClick={handleCancel}>
|
|
Cancel Request
|
|
</button>
|
|
</div>
|
|
</div>
|
|
);
|
|
}
|
|
}
|
|
|
|
ResponseTimer.propTypes = {
|
|
handleCancel: PropTypes.func.isRequired,
|
|
loadStartTime: PropTypes.number.isRequired
|
|
};
|
|
|
|
export default ResponseTimer;
|