ChartScreen.jsx 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. import { h, render, Component } from 'preact'; // eslint-disable-line no-unused-vars
  2. import HeaderLightItem from './partials/HeaderLightItem.jsx';
  3. import GraphItem from './partials/GraphItem.jsx';
  4. // displays the current Chart Screen depending on mode
  5. export default class ChartScreen extends Component {
  6. // RENDER
  7. render () {
  8. const question = this.props.questions[this.props.currentQuestion];
  9. let textKey;
  10. // get text depending on mode
  11. switch (this.props.mode) {
  12. case 'presentation':
  13. textKey = 'answer1';
  14. break;
  15. case 'comparison':
  16. textKey = 'answer2';
  17. break;
  18. default:
  19. textKey = 'text';
  20. break;
  21. }
  22. // ... combine and render it
  23. return (
  24. <section className="wrapper wrapper__question">
  25. <HeaderLightItem { ...this.props } />
  26. <main className="wrapper__main wrapper--centered wrapper__main--question">
  27. <div className="question question__manipula">
  28. <p className="question__title">
  29. {question.texts[this.props.currentStep][textKey].split('\n').map(item => <span>{item}<br /></span>)}
  30. </p>
  31. { this.props.mode === 'interaction'
  32. ? <p className="question__instruction">{question.texts[this.props.currentStep].instruction}</p> : []
  33. }
  34. { question.texts[this.props.currentStep].hint && this.props.mode === 'interaction'
  35. ? <p className="question__hint">
  36. {question.texts[this.props.currentStep].hint.split('\n').map(item => <span>{item}<br /></span>)}
  37. </p>
  38. : []
  39. }
  40. </div>
  41. <div className="question__message">
  42. <div className="question__message--error" aria-hidden="true">{this.props.error}</div>
  43. <div className="question__message--done" aria-hidden="true">{this.props.done}</div>
  44. </div>
  45. <GraphItem
  46. interactionData={this.props.interactionData}
  47. comparisonData={this.props.comparisonData}
  48. currentStep={this.props.currentStep}
  49. currentQuestion={this.props.currentQuestion}
  50. data={this.props.data}
  51. mode={this.props.mode}
  52. questions={this.props.questions}
  53. setData={this.props.setData} />
  54. <div className="question__source">{question.source}</div>
  55. </main>
  56. {this.props.mode !== 'interaction' || this.props.interactionData.length > 0
  57. ? <footer className="footer footer--chart">
  58. <a href="#" title={this.props.next} className="button--wide" onClick={() => this.props.toNextStep()}>
  59. {this.props.next}
  60. </a>
  61. </footer>
  62. : []
  63. }
  64. </section>
  65. );
  66. }
  67. }