<commit_before>import React, {Component} from 'react';
import {Link} from 'react-router';
import {connect} from 'react-redux';
import {toggleQuizView, editQuiz, deleteSavedQuiz, saveQuiz} from '../actions/eLearnActions';
import EditQuizItemView from '../components/EditQuizItemView';
import EditQuizTitleView from '../components/EditQuizTitleView';
import seedItem from '../utils/seedItem';

export const EditQuizItemsContainer = (props) => {

  const editQuizItem = (event) => {
    event.preventDefault();
    const target = event.target.id.split(" ");
    const itemIndex = target[0];
    const itemName = target[1];
    const value = event.target.value;
    const subIndex = target[2];
    props.editQuiz(itemIndex, itemName, value, subIndex)
  };

  const deleteQuiz = () => {
    let result = confirm("Confirm to delete quiz. This cannot be undone.")
    console.log("confirmed? ", result);
    if(result) {
      if(props.quizSelectedId) {
        props.deleteSavedQuiz(props.token, props.userId, props.courseId, props.quizSelectedId)
      } else props.editQuiz(0, "deleteQuiz");
    }
  }

  const saveQuiz = () => {
    props.saveQuiz(props.token, props.userId, props.courseId, props.quiz)
  }

  const formSubmit = (e) => {
    e.preventDefault();
    deleteQuiz();
  }

  let items = props.items.map((item, index) => {
    return (
      <EditQuizItemView
        key={index}
        question={item.question}
        answers={item.answers}
        index={index}
        editQuizItem={editQuizItem}
      />
    );
  });

  return (
    <div className="editQuiz-container">
      <div className="backToQuizList">
        <div>
        </div>
        <Link to="/quiz" >
          <button id="toggleQuizView" className="toggleQuizView">Back to Quizzes
          </button>
        </Link>
        <div>
          <h3>{props.message}</h3>
        </div>
      </div>
      <EditQuizTitleView
        title={props.title}
        minimumScore={props.minimumScore}
        editQuizItem= {editQuizItem}
        saveQuiz={saveQuiz}
        deleteQuiz={deleteQuiz}
      />
      {items}
      <div className="addItem">
        <button id="0 addItem" name="0 addItem" className="addItem-button" onClick={editQuizItem}>Add Question</button>
      </div>
    </div>
  );
};

// QuizPage.propTypes

function mapStateToProps(state) {
  return {
    quiz: state.quizReducer.quiz,
    quizSelectedId: state.quizReducer.quizSelectedId,
    items: state.quizReducer.quiz.items,
    title: state.quizReducer.quiz.title,
    minimumScore: state.quizReducer.quiz.minimumScore,
    courseId: state.authReducer.course._id,
    token: state.authReducer.token,
    userId: state.authReducer._id,
    message: state.quizReducer.message

  };
}
function mapDispatchToProps(dispatch) {
  return {
    toggleQuizView: () => dispatch(toggleQuizView()),
    editQuiz: (itemIndex, itemName, value, subIndex) => dispatch(editQuiz(itemIndex, itemName, value, subIndex)),
    deleteSavedQuiz: (token, userId, courseId, quizId) => dispatch(deleteSavedQuiz(token, userId, courseId, quizId)),
    saveQuiz: (token, userId, courseId, quiz) => dispatch(saveQuiz(token, userId, courseId, quiz))
  };
}
export default connect(
  mapStateToProps,
  mapDispatchToProps
)(EditQuizItemsContainer);<commit_msg>CRUD operations on quiz functional<commit_after>import React, {Component} from 'react';
import {Link} from 'react-router';
import {connect} from 'react-redux';
import {toggleQuizView, editQuiz, deleteSavedQuiz, saveQuiz} from '../actions/eLearnActions';
import EditQuizItemView from '../components/EditQuizItemView';
import EditQuizTitleView from '../components/EditQuizTitleView';
import seedItem from '../utils/seedItem';

export const EditQuizItemsContainer = (props) => {

  const editQuizItem = (event) => {
    event.preventDefault();
    const target = event.target.id.split(" ");
    const itemIndex = target[0];
    const itemName = target[1];
    const value = event.target.value;
    const subIndex = target[2];
    props.editQuiz(itemIndex, itemName, value, subIndex)
  };

  const deleteQuiz = () => {
    let result = confirm("Confirm to delete quiz. This cannot be undone.")
    console.log("confirmed? ", result);
    if(result) {
      if(props.quizSelectedId) {
        props.deleteSavedQuiz(props.token, props.userId, props.courseId, props.quizSelectedId)
      } else props.editQuiz(0, "deleteQuiz");
    }
  }

  const saveQuiz = () => {
    props.saveQuiz(props.token, props.userId, props.courseId, props.quiz)
  }

  const formSubmit = (e) => {
    e.preventDefault();
    deleteQuiz();
  }

  let items = props.items.map((item, index) => {
    return (
      <EditQuizItemView
        key={index}
        question={item.question}
        answers={item.answers}
        index={index}
        editQuizItem={editQuizItem}
      />
    );
  });

  return (
    <div className="editQuiz-container">
      <div className="backToQuizList">
        <div>
        </div>
        <Link to="/quiz" >
          <button id="toggleQuizView" className="toggleQuizView">Back to Quizzes
          </button>
        </Link>
        <div>
          <h3>{props.message}</h3>
        </div>
      </div>
      <EditQuizTitleView
        title={props.title}
        minimumScore={props.minimumScore}
        editQuizItem= {editQuizItem}
        saveQuiz={saveQuiz}
        deleteQuiz={deleteQuiz}
      />
      {items}
      <div className="addItem">
        <button id="0 addItem" name="0 addItem" className="addItem-button" onClick={editQuizItem}>Add Question</button>
      </div>
    </div>
  );
};

// QuizPage.propTypes

function mapStateToProps(state) {
  return {
    quiz: state.quizReducer.quiz,
    quizSelectedId: state.quizReducer.quiz._id,
    items: state.quizReducer.quiz.items,
    title: state.quizReducer.quiz.title,
    minimumScore: state.quizReducer.quiz.minimumScore,
    courseId: state.authReducer.course._id,
    token: state.authReducer.token,
    userId: state.authReducer._id,
    message: state.quizReducer.message

  };
}
function mapDispatchToProps(dispatch) {
  return {
    toggleQuizView: () => dispatch(toggleQuizView()),
    editQuiz: (itemIndex, itemName, value, subIndex) => dispatch(editQuiz(itemIndex, itemName, value, subIndex)),
    deleteSavedQuiz: (token, userId, courseId, quizId) => dispatch(deleteSavedQuiz(token, userId, courseId, quizId)),
    saveQuiz: (token, userId, courseId, quiz) => dispatch(saveQuiz(token, userId, courseId, quiz))
  };
}
export default connect(
  mapStateToProps,
  mapDispatchToProps
)(EditQuizItemsContainer);
{'fraction_non_alphanumeric': 0.1357610848697242, 'fraction_numerical': 0.0024379094926100867, 'mean_word_length': 3.3070866141732282, 'pattern_counts': {'":': 0, '<': 43, '<?xml version=': 0, '>': 63, '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': '963481', 'n_tokens_mistral': 2157, 'n_tokens_neox': 2121, 'n_words': 413}