2019-11-26 22:14:44 +05:30
|
|
|
import React, { PureComponent } from 'react';
|
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
import BezierEasing from 'bezier-easing';
|
2021-06-25 20:11:27 +05:30
|
|
|
import GreenPass from '../../../assets/icons/green-pass';
|
2020-12-16 02:02:52 -06:00
|
|
|
import { withTranslation } from 'react-i18next';
|
2019-11-26 22:14:44 +05:30
|
|
|
|
|
|
|
const propTypes = {
|
2021-03-23 15:29:16 -05:00
|
|
|
block: PropTypes.string,
|
2020-12-16 02:02:52 -06:00
|
|
|
completedPercent: PropTypes.number,
|
2021-03-23 15:29:16 -05:00
|
|
|
superBlock: PropTypes.string,
|
2020-12-16 02:02:52 -06:00
|
|
|
t: PropTypes.func.isRequired
|
2019-11-26 22:14:44 +05:30
|
|
|
};
|
|
|
|
|
|
|
|
export class CompletionModalBody extends PureComponent {
|
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
|
|
|
|
|
|
|
this.state = {
|
|
|
|
progressInterval: null,
|
|
|
|
shownPercent: 0
|
|
|
|
};
|
|
|
|
|
|
|
|
this.animateProgressBar = this.animateProgressBar.bind(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
animateProgressBar(completedPercent) {
|
|
|
|
const easing = BezierEasing(0.2, 0.5, 0.4, 1);
|
|
|
|
|
|
|
|
if (completedPercent > 100) completedPercent = 100;
|
|
|
|
if (completedPercent < 0) completedPercent = 0;
|
|
|
|
|
|
|
|
const transitionLength = completedPercent * 10 + 750;
|
|
|
|
const intervalLength = 10;
|
|
|
|
const intervalsToFinish = transitionLength / intervalLength;
|
|
|
|
const amountPerInterval = completedPercent / intervalsToFinish;
|
|
|
|
let percent = 0;
|
|
|
|
|
|
|
|
const myInterval = setInterval(() => {
|
|
|
|
percent += amountPerInterval;
|
|
|
|
|
|
|
|
if (percent > completedPercent) percent = completedPercent;
|
|
|
|
|
|
|
|
this.setState({
|
|
|
|
shownPercent: Math.round(
|
|
|
|
completedPercent * easing(percent / completedPercent)
|
|
|
|
)
|
|
|
|
});
|
|
|
|
|
|
|
|
if (percent >= completedPercent) clearInterval(myInterval);
|
|
|
|
}, intervalLength);
|
|
|
|
|
|
|
|
this.setState({
|
|
|
|
progressInterval: myInterval
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
componentWillUnmount() {
|
|
|
|
clearInterval(this.state.progressInterval);
|
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
2021-03-23 15:29:16 -05:00
|
|
|
const { block, completedPercent, superBlock, t } = this.props;
|
|
|
|
const blockTitle = t(`intro:${superBlock}.blocks.${block}.title`);
|
2019-11-26 22:14:44 +05:30
|
|
|
|
|
|
|
return (
|
|
|
|
<>
|
|
|
|
<div className='completion-challenge-details'>
|
|
|
|
<GreenPass
|
|
|
|
className='completion-success-icon'
|
|
|
|
onAnimationEnd={() => {
|
|
|
|
setTimeout(() => {
|
|
|
|
this.animateProgressBar(completedPercent);
|
|
|
|
}, 50);
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
<div className='completion-block-details'>
|
2021-03-23 15:29:16 -05:00
|
|
|
<div className='completion-block-name'>{blockTitle}</div>
|
2019-11-26 22:14:44 +05:30
|
|
|
<div className='progress-bar-wrap'>
|
|
|
|
<div className='progress-bar-background'>
|
2020-12-16 02:02:52 -06:00
|
|
|
{t('learn.percent-complete', {
|
|
|
|
percent: this.state.shownPercent
|
|
|
|
})}
|
2019-11-26 22:14:44 +05:30
|
|
|
</div>
|
|
|
|
<div
|
|
|
|
className='progress-bar-percent'
|
|
|
|
style={{ width: this.state.shownPercent + '%' }}
|
|
|
|
>
|
|
|
|
<div className='progress-bar-foreground'>
|
2020-12-16 02:02:52 -06:00
|
|
|
{t('learn.percent-complete', {
|
|
|
|
percent: this.state.shownPercent
|
|
|
|
})}
|
2019-11-26 22:14:44 +05:30
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
CompletionModalBody.displayName = 'CompletionModalBody';
|
|
|
|
CompletionModalBody.propTypes = propTypes;
|
|
|
|
|
2020-12-16 02:02:52 -06:00
|
|
|
export default withTranslation()(CompletionModalBody);
|