Files
freeCodeCamp/client/src/templates/Challenges/components/CompletionModalBody.js

106 lines
2.9 KiB
JavaScript
Raw Normal View History

import React, { PureComponent } from 'react';
import PropTypes from 'prop-types';
import BezierEasing from 'bezier-easing';
feat(client): migrate icons to TS (#42453) * migrate files and update tests fix: use more memory for gatsby develop (#42433) feat(client): remove whitespace from calculated values (#42400) * feat(client?): remove whitespace for calculated values * feat(client): remove whitespace from styledeclaration * do not automatically strip Co-authored-by: Oliver Eyton-Williams <ojeytonwilliams@gmail.com> * fix: include all properties of CSSStyleDeclaration * fix test for getPropVal Co-authored-by: Oliver Eyton-Williams <ojeytonwilliams@gmail.com> fix: get showUpcomingChange from env.json (#42440) fix(client): display legacy certs like current ones (#42038) * fix: display legacy certs like the current ones * fix: link projects in legacy certs to project pages * fix: update tests to changed legacy cert display * fix: update tests for removed legacy certs forms * fix: display legacy certs like the current ones * fix: submit projects for cert on projects pages * fix: remove legacy certs form submitting handling * fix: move claiming cert setup before both tests * fix: remove legacy cert update props and actions * fix: remove legacy cert updates from api * fix: correct merge conflict fix(curriculum): rework Project Euler 98 (#42423) * fix: rework challenge to use argument in function * fix: add solution * fix: use MathJax to improve math notation fix(curriculum): rework Project Euler 56 (#42364) * fix: rework challenge to use argument in function * fix: add solution * fix: use MathJax to improve look of math notation fix(curriculum): correct small english typo (#42447) chore: group together monaco-editor and plugin (#42443) This should get renovate to create PRs where both are modified. fix(deps): update dependency algoliasearch to v4.9.2 (#42432) Co-authored-by: Renovate Bot <bot@renovateapp.com> migrate files and update tests Algorithm moved to TSX first ten files renamed to tsx first 10 migration complete first 20 files renamed migrate some files. rename all test index.tsx forced to ignore ts issues rename and migrate all files update tests * remove missed propType declarations * kebab-caseify * fi xlinting Co-authored-by: Oliver Eyton-Williams <ojeytonwilliams@gmail.com> Co-authored-by: Parth Parth <thecodingaviator@users.noreply.github.com> Co-authored-by: Shaun Hamilton <shauhami020@gmail.com>
2021-06-25 20:11:27 +05:30
import GreenPass from '../../../assets/icons/green-pass';
import { withTranslation } from 'react-i18next';
const propTypes = {
block: PropTypes.string,
completedPercent: PropTypes.number,
superBlock: PropTypes.string,
t: PropTypes.func.isRequired
};
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() {
const { block, completedPercent, superBlock, t } = this.props;
const blockTitle = t(`intro:${superBlock}.blocks.${block}.title`);
return (
<>
<div className='completion-challenge-details'>
<GreenPass
className='completion-success-icon'
onAnimationEnd={() => {
setTimeout(() => {
this.animateProgressBar(completedPercent);
}, 50);
}}
/>
</div>
<div className='completion-block-details'>
<div className='completion-block-name'>{blockTitle}</div>
<div className='progress-bar-wrap'>
<div className='progress-bar-background'>
{t('learn.percent-complete', {
percent: this.state.shownPercent
})}
</div>
<div
className='progress-bar-percent'
style={{ width: this.state.shownPercent + '%' }}
>
<div className='progress-bar-foreground'>
{t('learn.percent-complete', {
percent: this.state.shownPercent
})}
</div>
</div>
</div>
</div>
</>
);
}
}
CompletionModalBody.displayName = 'CompletionModalBody';
CompletionModalBody.propTypes = propTypes;
export default withTranslation()(CompletionModalBody);