{"size": 1111, "ext": "js", "max_stars_repo_path": "src/components/QuizGame/PlayQuizGame.js", "max_stars_repo_name": "gagamil/quizapp", "max_stars_repo_stars_event_min_datetime": "2018-06-21T06:37:03.000Z", "max_stars_repo_stars_event_max_datetime": "2020-12-19T20:31:02.000Z", "max_issues_repo_path": "src/components/QuizGame/PlayQuizGame.js", "max_issues_repo_name": "gagamil/quizapp", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/components/QuizGame/PlayQuizGame.js", "max_forks_repo_name": "gagamil/quizapp", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": 2, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 32.6764705882, "max_line_length": 113, "alphanum_fraction": 0.7290729073}
import React, { Component } from 'react';
import QuizElementChoicePick from './__QuizElementChoicePick/ScoreQuiz__QuizElementChoicePick';
import { Quiz } from '../CreateQuiz/QuizModels'; 


/**
 * state userChoices - {element:key, elementChoice:key, score:val}
 */
class PlayQuizGame extends Component {
  constructor(props) {
    super(props);
    this.state = {quiz:this.props.quiz, currQuestionCount: 1, userChoices:[]};
  }

  choiceSubmit(choiceKey, elementId, score){
    const updatedUserChoices = [...this.state.userChoices, {elementId:elementId, choice:choiceKey, score:score}];
    const nextQuestionCount = this.state.currQuestionCount+1;
    this.setState({userChoices: updatedUserChoices, currQuestionCount:nextQuestionCount});
     
    if(nextQuestionCount > this.state.quiz.elements.length){
      this.props.onComplete(updatedUserChoices);
    }
  }

  render() {
    const q = this.state.quiz.elements[this.state.currQuestionCount-1];
    return (
        <QuizElementChoicePick quizElementData={q} submitChoiceValue={this.choiceSubmit.bind(this)}/>
    );
  }
}

export default PlayQuizGame;
