import React, { PropTypes, PureComponent } from 'react';
import { bindActionCreators } from 'redux';
import { connect } from 'react-redux';
import { createSelector } from 'reselect';
import { Col, Row } from 'react-bootstrap';
import Choice from './Choice.jsx';
import {
currentIndexSelector,
selectedChoiceSelector,
nextQuestion,
selectChoice,
correctSelector,
incrementCorrect,
resetQuiz,
resetChoice
} from './redux';
import { submitChallenge, challengeMetaSelector } from '../../redux';
import { challengeSelector } from '../../../../redux';
const mapStateToProps = createSelector(
challengeSelector,
challengeMetaSelector,
currentIndexSelector,
selectedChoiceSelector,
correctSelector,
(
{
description = [],
title
},
meta,
currentIndex,
selectedChoice,
correct
) => ({
title,
description,
meta,
currentIndex,
selectedChoice,
correct
})
);
function mapDispatchToProps(dispatch) {
return () => bindActionCreators({
nextQuestion,
selectChoice,
incrementCorrect,
resetQuiz,
resetChoice,
submitChallenge
}, dispatch);
}
const propTypes = {
correct: PropTypes.number,
currentIndex: PropTypes.number,
description: PropTypes.string,
meta: PropTypes.object,
nextQuestion: PropTypes.fun,
resetChoice: PropTypes.fun,
resetQuiz: PropTypes.fun,
selectedChoice: PropTypes.number,
submitChallenge: PropTypes.fun
};
export class QuizChallenge extends PureComponent {
constructor(props) {
super(props);
this.nextQuestion = this.nextQuestion.bind(this);
this.submitChallenge = this.submitChallenge.bind(this);
}
nextQuestion() {
this.props.resetChoice();
this.props.nextQuestion();
}
submitChallenge() {
this.props.resetQuiz();
this.props.submitChallenge();
}
renderTitle() {
return (
{this.props.meta.title}
You got {this.props.correct} out of {this.props.description.length} correct!
{isQuizPassed === false ? (You will need to get all the questions correct in order to mark this quiz as completed.