<commit_before>import { hashToCollection } from '../../libs/hashToCollection';
import _ from 'underscore';
import generateFeedbackString from './generateFeedbackString.js';
import {
  incrementResponseCount,
  submitNewResponse,
  findResponseByText
} from '../../actions/responses.js';

const getLatestAttempt = function (attempts = []) {
  const lastIndex = attempts.length - 1;
  return attempts[lastIndex];
};

export default function updateResponseResource(returnValue, questionID, attempts, dispatch, playQuestion) {
  let previousAttempt;

  const preAtt = getLatestAttempt(attempts);
  if (preAtt) { previousAttempt = getLatestAttempt(attempts).response; }
  const prid = previousAttempt ? previousAttempt.key : undefined;
  const isFirstAttempt = !preAtt

  if (returnValue.found && returnValue.response.key) {
    dispatch(
      incrementResponseCount(questionID, returnValue.response.key, prid, isFirstAttempt)
    );
  } else {
    incrementOrCreateResponse(questionID, returnValue, prid, dispatch, isFirstAttempt);
  }
}

export function incrementOrCreateResponse(questionID, returnValue, prid, dispatch, isFirstAttempt) {
  const callback = (response) => {
    if (response) {
      dispatch(
        incrementResponseCount(questionID, response.key, prid, isFirstAttempt)
      );
    } else {
      dispatch(
        submitNewResponse(returnValue.response, prid, isFirstAttempt)
      );
    }
  };
  findResponseByText(returnValue.response.text, questionID, callback);
}
<commit_msg>removes deprecated code from update responses<commit_after>import { hashToCollection } from '../../libs/hashToCollection';
import _ from 'underscore';
import generateFeedbackString from './generateFeedbackString.js';
import {
  incrementResponseCount,
  submitResponse,
  findResponseByText
} from '../../actions/responses.js';

const getLatestAttempt = function (attempts = []) {
  const lastIndex = attempts.length - 1;
  return attempts[lastIndex];
};

export default function updateResponseResource(returnValue, questionID, attempts, dispatch, playQuestion) {
  let previousAttempt;
  const preAtt = getLatestAttempt(attempts);
  if (preAtt) { previousAttempt = getLatestAttempt(attempts).response; }
  const prid = previousAttempt ? previousAttempt.key : undefined;
  const isFirstAttempt = !preAtt;
  dispatch(
    submitResponse(returnValue.response, prid, isFirstAttempt)
  );
}

{'fraction_non_alphanumeric': 0.1051529116045245, 'fraction_numerical': 0.0008378718056137411, 'mean_word_length': 4.867321867321867, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 4, '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': '6813896', 'n_tokens_mistral': 689, 'n_tokens_neox': 660, 'n_words': 152}