import React, {Component, PropTypes} from 'react'; import {REQUEST_TIME_TO_SHOW_COUNTER} from '../../common/constants'; class ResponseTimer extends Component { 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 (
{elapsedTime > REQUEST_TIME_TO_SHOW_COUNTER ? (

{elapsedTime} seconds...

) : (

Loading...

)}

) } } ResponseTimer.propTypes = { handleCancel: PropTypes.func.isRequired, loadStartTime: PropTypes.number.isRequired, }; export default ResponseTimer;