@bigfishtv/cockpit
Version:
57 lines (43 loc) • 2.48 kB
JavaScript
var _class, _temp;
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
import React, { Component } from 'react';
var ProgressBarPredictive = (_temp = _class = function (_Component) {
_inherits(ProgressBarPredictive, _Component);
function ProgressBarPredictive(props) {
_classCallCheck(this, ProgressBarPredictive);
var _this = _possibleConstructorReturn(this, _Component.call(this));
_this.startTime = new Date().getTime();
_this.mounted = true;
_this.state = {
progress: 0
};
return _this;
}
ProgressBarPredictive.prototype.componentDidMount = function componentDidMount() {
var _this2 = this;
this.checkTime();
this.animationInterval = setInterval(function () {
return _this2.checkTime();
}, 1000 / 10);
};
ProgressBarPredictive.prototype.componentWillUnmount = function componentWillUnmount() {
this.mounted = false;
if (this.animationInterval) clearInterval(this.animationInterval);
};
ProgressBarPredictive.prototype.checkTime = function checkTime() {
var currentTime = new Date().getTime();
var elapsedTime = currentTime - this.startTime;
var progress = elapsedTime / this.props.estimatedTime * 100;
if (!this.mounted || progress >= 100) clearInterval(this.animationInterval);
if (this.mounted) this.setState({ progress: progress });
};
ProgressBarPredictive.prototype.render = function render() {
return React.createElement('progress', { value: this.state.progress, max: 100, style: { marginLeft: 15, marginRight: 15 } });
};
return ProgressBarPredictive;
}(Component), _class.defaultProps = {
estimatedTime: 5000
}, _temp);
export { ProgressBarPredictive as default };