import { h, render, Component } from 'preact'; // eslint-disable-line no-unused-vars import GraphItem from './partials/GraphItem.jsx'; import IntroItem from './partials/IntroItem.jsx'; import QuestionItem from './partials/QuestionItem.jsx'; import UserVoteItem from './partials/UserVoteItem.jsx'; import HeaderLightItem from './partials/HeaderLightItem.jsx'; // module02: Question Screen // outputs the wrapper which contains // - a) the current question // - b) the current user vote result // - c) the initial intro item export default class QuestionScreen extends Component { // get answer and validate it getAnswers (question) { return Object.prototype.hasOwnProperty.call(question, 'antworten') ? question.antworten : []; } // RENDER render () { let topItem = ''; // content (will either be questions or statistics) let isCorrectClass = ''; let isIncorrectClass = ''; let buttonLabel = this.props.next; const question = this.props.questions[this.props.currentQuestion]; const answers = this.getAnswers(question); // set classes to style lines in svg graph const hasAnswered = this.props.currentAnswerIndex !== null; const correct = answers.find(item => item.korrekt === true); if (this.props.currentGroup === 1 && hasAnswered) { isCorrectClass = `correct--${answers.indexOf(correct) + 1}`; isIncorrectClass = !this.props.currentAnswerCorrect ? `incorrect--${this.props.currentAnswerIndex + 1}` : ''; } else if (this.props.currentGroup === 2) { isCorrectClass = this.props.currentAnswerCorrect ? 'correct' : 'incorrect'; buttonLabel = `${this.props.success} ${this.props.next}`; } // d3js properties to pass through const graphItemProps = { dataSet: question, setData: this.props.setData, chartMode: this.props.chartMode, currentQuestion: this.props.currentQuestion, points: this.props.points }; // render sub component depending on chartMode if (this.props.chartMode === 'question') { topItem = ; } else if (this.props.voteRatios !== null) { topItem = ; } else { topItem = ; } // output return (
{topItem}
); } }