import React from 'react'; class Register extends React.Component { constructor(props) { super(props) this.state = { showIntro: false, hasSentenceFragment: this.hasSentenceFragment(), } } landingPageHtmlHasText(){ const { lesson, } = this.props // strips out everything nested betwee < and >. // we should also not allow draft js to send text-less answers from // the lp editor return lesson.landingPageHtml.replace(/(<([^>]+)>)/ig, "").length > 0; } startActivity = () => { const { lesson, startActivity, } = this.props if (lesson.landingPageHtml && this.landingPageHtmlHasText()) { this.setState({ showIntro: true, }); } else { startActivity(); } } handleStartLessonClick = () => { const { startActivity, } = this.props startActivity(); } resume = () => { const { resumeActivity, session, } = this.props resumeActivity(session); } hasSentenceFragment = () => { const { lesson, } = this.props const { questions } = lesson; for (let i = 0; i < questions.length; i+=1) { if (questions[i].questionType === "sentenceFragments") { return true; } } return false; } renderButton = () => { const { session, } = this.props let onClickFn, text; if (session) { // resume session if one is passed onClickFn = this.resume; text = Resume; } else { // otherwise begin new session onClickFn = this.startActivity; text = Begin; } return ( ); } renderIntro = () => { const { lesson, } = this.props const { showIntro, hasSentenceFragment, } = this.state if (showIntro) { return (
); } else if (hasSentenceFragment) { return (

Welcome to Quill Connect Fragments!

  • Add to the group of words to make a complete sentence.
  • Add the number of words shown in the directions.
  • There is often more than one correct answer.
  • Remember to use correct spelling, capitalization, and punctuation!
{this.renderButton()}
); } else { return (

Welcome to Quill Connect!

  • Combine the sentences together into one sentence.
  • You may add or remove words.
  • There is often more than one correct answer.
  • Remember to use correct spelling, capitalization, and punctuation!
{this.renderButton()}
); } } render() { return (
{this.renderIntro()}
); } } export { Register }