Advertisement
Guest User

Untitled

a guest
Jul 23rd, 2019
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.83 KB | None | 0 0
  1. import React, {Component} from 'react';
  2. import { translate } from 'react-i18next';
  3. import PropTypes from 'prop-types';
  4. import { Progress } from 'react-sweet-progress';
  5. import CloseBtn from '../../components/CloseBtn';
  6. import PlayersCount from '../../components/PlayersCount';
  7. import QuestionAt from '../../components/QuestionAt';
  8. import "react-sweet-progress/lib/style.css";
  9. import {calcPercent, getCurrentUser} from "../../utils/helper";
  10.  
  11. let timer;
  12.  
  13. class WrongAnsweredPage extends Component {
  14. constructor(props) {
  15. super(props);
  16.  
  17. this.state = {
  18. countdown: props.countdown,
  19. isUsedFeebies: false,
  20. questionIndex: props.questionIndex,
  21. buttonStatus: 'default',
  22. }
  23. }
  24.  
  25. componentDidMount() {
  26. const __this = this;
  27.  
  28. let interval = 1000 * this.props.countdown / (this.props.countdown + 1);
  29.  
  30. timer = window.setInterval(function () {
  31. __this.timerAction();
  32. }, interval)
  33. }
  34.  
  35. timerAction() {
  36. if (this.state.countdown > 0) {
  37. const countdown = this.state.countdown - 1;
  38. this.setState({countdown})
  39. } else {
  40. this.props.goToVideo();
  41. clearInterval(timer);
  42. }
  43. }
  44.  
  45. componentWillUnmount() {
  46. clearInterval(timer);
  47. }
  48.  
  49. static getDerivedStateFromProps (nextProps, prevState) {
  50. if(prevState.questionIndex !== nextProps.questionIndex) {
  51. return {
  52. countdown: nextProps.countdown,
  53. isUsedFeebies: false,
  54. questionIndex: nextProps.questionIndex
  55. }
  56. }
  57. return null;
  58. }
  59.  
  60. useFreebies = () => {
  61. const currentUser = getCurrentUser();
  62. if(this.state.isUsedFeebies || currentUser.freebie < 1) return;
  63.  
  64. this.setState({isUsedFeebies: true, buttonStatus: 'clicked'});
  65.  
  66. const buttonDiv = document.getElementsByClassName("react-sweet-progress-circle-outer")[0];
  67. const buttonTxtDiv = document.getElementsByClassName("life-btn--text")[0]
  68. buttonDiv.style.backgroundColor = "rgb(73, 152, 0)";
  69. buttonTxtDiv.style.color = 'black';
  70.  
  71. this.props.useFreebies();
  72.  
  73. };
  74.  
  75. render() {
  76.  
  77. const percent = calcPercent(this.props.countdown, this.state.countdown);
  78. const { t } = this.props;
  79. const { buttonStatus } = this.state;
  80. const currentUser = getCurrentUser();
  81.  
  82. const useFreebieVisible = this.props.questionIndex !== this.props.questionCount &&
  83. ( currentUser.freebie > 0 || (this.state.isUsedFeebies && currentUser.freebie === 0)) ;
  84.  
  85. return (
  86. <div className="wronganswered main-wrap">
  87. <header className="header">
  88. <div className="container">
  89. <PlayersCount count={this.props.playersCount}/>
  90. <CloseBtn/>
  91. </div>
  92. </header>
  93.  
  94. <div className="content">
  95. <div className="container">
  96. <div className="eliminated">
  97. <div className="main-title line-red"><span>Eliminated</span></div>
  98.  
  99. <div className="level-reached">
  100. <div className="level-reached--title">Level reached</div>
  101. <QuestionAt
  102. cls="positioin-left"
  103. questionCount={this.props.questionCount}
  104. questionIndex={this.props.questionIndex}
  105. />
  106. </div>
  107.  
  108. <div className="level-reached">
  109. <div className="level-reached--title">Total Lives</div>
  110. <div>
  111. <div className="questions-counter positioin-left" style={{ display: 'inline-block' }}>
  112. <img className="life-btn--img" src="/assets/images/icons/heart-icon.png" alt="life" title="life" />&nbsp;<span>{currentUser.freebie}</span>
  113. </div>
  114. { buttonStatus === 'clicked' &&
  115. <div className="questions-counter positioin-right" style={{display: 'inline-block', float: 'right' }}>
  116. <span style={{color: 'red'}}>-1</span>
  117. </div>
  118. }
  119. </div>
  120. </div>
  121.  
  122. { useFreebieVisible ?
  123. <a className="life-btn" onClick={this.useFreebies}>
  124. <div className="circle-countdown-wrap" style={{textAlign: 'center'}}>
  125. <Progress
  126. type="circle"
  127. percent={percent}
  128. status="default"
  129. theme={{
  130. default: {
  131. symbol: '',
  132. color: 'rgb(95, 235, 14)',
  133. trailColor: 'rgb(24, 51, 1)',
  134. }
  135. }}
  136. width={100}
  137. strokeWidth={6}
  138. className="countdown-circle"
  139. />
  140.  
  141. <div className="progressbar-text">
  142. <div className="life-btn--content">
  143. <img className="life-btn--img" src="/assets/images/icons/heart-icon.png" alt="life" title="life" />
  144. <div className="life-btn--text">Use extra life?</div>
  145. </div>
  146. </div>
  147. </div>
  148. </a> : <div className="freebie-empty"/>
  149. }
  150.  
  151.  
  152. { this.props.questionIndex !== this.props.questionCount &&
  153. <div className="base-btn-wrap">
  154. <a title="" className="base-btn btn-white" onClick={this.props.continueWatching}>{t('continue watching')}</a>
  155. </div>
  156. }
  157. </div>
  158. </div>
  159. </div>
  160.  
  161. <div className="fullscreen-bg mobile"><img src="/assets/images/backgrounds/black-background.jpg" alt="background"/></div>
  162. </div>
  163. )
  164. }
  165. }
  166.  
  167.  
  168. WrongAnsweredPage.propTypes = {
  169. useFreebies: PropTypes.func,
  170. continueWatching: PropTypes.func,
  171. playersCount: PropTypes.number,
  172. questionCount: PropTypes.number,
  173. questionIndex: PropTypes.number,
  174. countdown: PropTypes.number,
  175. goToVideo: PropTypes.func
  176. };
  177.  
  178. export default translate("translations")(WrongAnsweredPage)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement