<commit_before>import React, { Component } from "react";
import fetchContainer from "../../containers/fetch-container";
import Slide from "../Slide/Slide";
import Results from '../Results/Results';
import Loading from '../Loading/Loading';
import { storeTestInfo } from '../../utils/usersAPI';
import './Assessments.css';
import { Redirect } from 'react-router';
import { Link } from 'react-router-dom';

class Assessments extends Component {
  constructor() {
    super();
    this.state = {
      counter: 0,
      loggedIn: true,
    };
    this.manageSlideUpdate = this.manageSlideUpdate.bind(this);
  }

  componentDidMount() {
    const { fetchAssessments, testType, user } = this.props;

    if (!user) {
      this.setState({ loggedIn: false })
    } else {
      fetchAssessments(testType);
    }
  }

  componentWillReceiveProps(nextProps) {
    const objectKeys = Object.keys(nextProps.fetchedAssessment);
    if (objectKeys.length > 0 && this.props.assessmentSlides.length === 0) {
      const { id, deck_id } = nextProps.fetchedAssessment
      const { user } = this.props
      this.props.displayAssessment(id);
      storeTestInfo(id, deck_id, user.id)
    }
  }

  manageSlideUpdate(object, boolean) {
    const { fetchedAssessment } = this.props;
    object.response = boolean;

    this.props.updateSlideResponse(object, fetchedAssessment.id);
    this.setState({ counter: this.state.counter + 1 });
  }

  render() {

    const { fetchHasErred, fetchIsLoading, assessmentSlides } = this.props;

    if (!this.state.loggedIn) {
      return <Redirect to='/login' />
    }
    if (fetchHasErred) {
      return <p>You fucked up</p>
    }
    if (fetchIsLoading) {
      return <Loading />
    }
    let slideToRender = assessmentSlides[this.state.counter];

    if (assessmentSlides.length > 0 && slideToRender !== undefined) {
      return (
        <div className='slide-container'>
          <Slide
            slideData={slideToRender}
            manageSlideUpdate={this.manageSlideUpdate}
          />
        </div>
      );
    }

    if (assessmentSlides.length > 0 && slideToRender === undefined) {
      return (
        <div className='completion-container'>
          <h3 className='completion-message'>You have completed your assessment!</h3>
          <Link to='/results' className='results-link'>
            View your results
          </Link>
        </div>
      )
    } else {
      return (
        <div>
          Everything's broken
        </div><commit_msg>refactor assessment component with suggestions from eval and new helper function<commit_after>import React, { Component } from "react";
import fetchContainer from "../../containers/fetch-container";
import Slide from "../Slide/Slide";
import Results from '../Results/Results';
import Loading from '../Loading/Loading';
import { storeTestInfo, handleFetchError, handleFetchLoading } from '../../utils/usersAPI';
import './Assessments.css';
import { Redirect } from 'react-router';
import { Link } from 'react-router-dom';

class Assessments extends Component {
  constructor() {
    super();
    this.state = {
      counter: 0,
      loggedIn: true,
    };
    this.manageSlideUpdate = this.manageSlideUpdate.bind(this);
  }

  componentDidMount() {
    const { fetchAssessments, testType, user } = this.props;

    if (!user) {
      this.setState({ loggedIn: false })
    } else {
      fetchAssessments(testType);
    }
  }

  componentWillReceiveProps(nextProps) {
    const objectKeys = Object.keys(nextProps.fetchedAssessment);
    if (objectKeys.length > 0 && this.props.assessmentSlides.length === 0) {
      const { id, deck_id } = nextProps.fetchedAssessment
      const { user } = this.props
      this.props.displayAssessment(id);
      storeTestInfo(id, deck_id, user.id)
    }
  }

  manageSlideUpdate(object, boolean) {
    const { fetchedAssessment } = this.props;
    object.response = boolean;

    this.props.updateSlideResponse(object, fetchedAssessment.id);
    this.setState({ counter: this.state.counter + 1 });
  }

  render() {

    const { fetchHasErred, fetchIsLoading, assessmentSlides } = this.props;

    if (!this.state.loggedIn) {
      return <Redirect to='/login' />
    }

    handleFetchError(fetchHasErred)
    handleFetchLoading(fetchIsLoading)

    let slideToRender = assessmentSlides[this.state.counter];

    if (assessmentSlides.length && slideToRender) {
      return (
        <div className='slide-container'>
          <Slide
            slideData={slideToRender}
            manageSlideUpdate={this.manageSlideUpdate}
          />
        </div>
      );
    }

    if (assessmentSlides.length && slideToRender === undefined) {
      return (
        <div className='completion-container'>
          <h3 className='completion-message'>You have completed your assessment!</h3>
          <Link to='/results' className='results-link'>
            View your results
          </Link>
        </div>
      )
    } else {
      return (
        <div>
          Everything's broken
        </div>
{'fraction_non_alphanumeric': 0.1272835583796664, 'fraction_numerical': 0.0027799841143764893, 'mean_word_length': 2.7091310751104567, 'pattern_counts': {'":': 0, '<': 30, '<?xml version=': 0, '>': 34, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7474800', 'n_tokens_mistral': 1501, 'n_tokens_neox': 1458, 'n_words': 316}