insomnia/app/ui/components/ResponseTimer.js
Gregory Schier b198e6170b React performance sweep (#96)
* Removed some unnecessary rendering

* Only PureComponents and some other stuff

* Removed all functional components

* Only deal with nunjucks marks

* Remove ref assign functions in modals

* Lots of tweaks

* A bit snappier

* A bit snappier
2017-02-28 13:32:23 -08:00

48 lines
1.1 KiB
JavaScript

import React, {PureComponent, PropTypes} from 'react';
import {REQUEST_TIME_TO_SHOW_COUNTER} from '../../common/constants';
class ResponseTimer extends PureComponent {
render () {
const {loadStartTime, className, handleCancel} = this.props;
if (loadStartTime < 0) {
return null;
}
// Set a timer to update the UI again soon
setTimeout(() => {
this.forceUpdate();
}, 100);
const millis = Date.now() - loadStartTime - 200;
const elapsedTime = Math.round(millis / 100) / 10;
return (
<div className={className}>
{elapsedTime > REQUEST_TIME_TO_SHOW_COUNTER ? (
<h2>{elapsedTime} seconds...</h2>
) : (
<h2>Loading...</h2>
)}
<br/>
<i className="fa fa-refresh fa-spin"></i>
<br/>
<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;