<commit_before>import { handleActions } from 'redux-actions';
import update from 'immutability-helper';
import { merge, union, difference } from 'lodash';

import { WRAP_UP_STARTING_COUNT } from './constants';
import quiz from 'features/quiz/actions';

export const initialQuizSessionState = {
  category: '',
  wrapUp: { active: false, count: 10 },
  synonymModalOpen: false,
  current: {},
  queue: [],
  correct: [],
  incorrect: [],
  complete: [],
};

const setCategory = (state, { payload }) =>
  update(state, {
    category: { $set: payload },
  });

const setSynonymModalOpen = (state, { payload }) =>
  update(state, {
    synonymModalOpen: { $set: payload },
  });

export const getWrapUpItems = (state) => {
  let needsReview = difference(state.incorrect, state.complete);
  if (needsReview.length < 10) {
    needsReview = [...needsReview, ...difference(state.queue, needsReview)].slice(
      0,
      WRAP_UP_STARTING_COUNT
    );
  }
  return needsReview;
};

const toggleWrapUp = (state) => {
  let { queue } = state;
  let count = WRAP_UP_STARTING_COUNT;
  const active = !state.wrapUp.active;

  if (active) {
    queue = getWrapUpItems(state);
    count = queue.length;
  }

  return update(state, {
    wrapUp: {
      active: { $set: active },
      count: { $set: count },
    },
    queue: { $set: queue },
  });
};

const decrementWrapUp = (state) =>
  state.wrapUp.active
    ? update(state, {
      wrapUp: { count: { $set: Math.max(state.wrapUp.count - 1, 0) } },
    })
    : state;

const replaceCurrent = (state, { payload }) =>
  update(state, {
    current: { $set: payload },
    queue: { $set: difference(state.queue, [state.current.id]) },
  });

const mergeCurrent = (state, { payload }) =>
  update(state, {
    current: { $set: merge({}, state.current, payload) },
  });

const rotateCurrent = (state, { payload }) =>
  update(state, {
    current: { $set: payload.newCurrent },
    queue: { $set: union(state.queue, [payload.currentId]) },
  });

const addIdToCorrect = (state, { payload }) =>
  update(state, {
    correct: { $set: union(state.correct, [payload]) },
  });

const addIdToIncorrect = (state, { payload }) =>
  update(state, {
    incorrect: { $set: union(state.incorrect, [payload]) },
  });

const addIdToComplete = (state, { payload }) =>
  update(state, {
    complete: { $set: union(state.complete, [payload]) },
  });

const removeIdFromQueue = (state, { payload }) =>
  update(state, {
    queue: { $set: difference(state.queue, [payload]) },
  });

const mergeQueue = (state, { payload }) =>
  update(state, {
    queue: {
      $set: union(state.queue, difference(payload.reviewIds, state.current.id)),
    },<commit_msg>fix: ensure current & complete ids are excluded by partial queue load<commit_after>import { handleActions } from 'redux-actions';
import update from 'immutability-helper';
import { merge, union, difference } from 'lodash';

import { WRAP_UP_STARTING_COUNT } from './constants';
import quiz from 'features/quiz/actions';

export const initialQuizSessionState = {
  category: '',
  wrapUp: { active: false, count: 10 },
  synonymModalOpen: false,
  current: {},
  queue: [],
  correct: [],
  incorrect: [],
  complete: [],
};

const setCategory = (state, { payload }) =>
  update(state, {
    category: { $set: payload },
  });

const setSynonymModalOpen = (state, { payload }) =>
  update(state, {
    synonymModalOpen: { $set: payload },
  });

export const getWrapUpItems = (state) => {
  let needsReview = difference(state.incorrect, state.complete);
  if (needsReview.length < 10) {
    needsReview = [...needsReview, ...difference(state.queue, needsReview)].slice(
      0,
      WRAP_UP_STARTING_COUNT
    );
  }
  return needsReview;
};

const toggleWrapUp = (state) => {
  let { queue } = state;
  let count = WRAP_UP_STARTING_COUNT;
  const active = !state.wrapUp.active;

  if (active) {
    queue = getWrapUpItems(state);
    count = queue.length;
  }

  return update(state, {
    wrapUp: {
      active: { $set: active },
      count: { $set: count },
    },
    queue: { $set: queue },
  });
};

const decrementWrapUp = (state) =>
  state.wrapUp.active
    ? update(state, {
      wrapUp: { count: { $set: Math.max(state.wrapUp.count - 1, 0) } },
    })
    : state;

const replaceCurrent = (state, { payload }) =>
  update(state, {
    current: { $set: payload },
    queue: { $set: difference(state.queue, [state.current.id]) },
  });

const mergeCurrent = (state, { payload }) =>
  update(state, {
    current: { $set: merge({}, state.current, payload) },
  });

const rotateCurrent = (state, { payload }) =>
  update(state, {
    current: { $set: payload.newCurrent },
    queue: { $set: union(state.queue, [payload.currentId]) },
  });

const addIdToCorrect = (state, { payload }) =>
  update(state, {
    correct: { $set: union(state.correct, [payload]) },
  });

const addIdToIncorrect = (state, { payload }) =>
  update(state, {
    incorrect: { $set: union(state.incorrect, [payload]) },
  });

const addIdToComplete = (state, { payload }) =>
  update(state, {
    complete: { $set: union(state.complete, [payload]) },
  });

const removeIdFromQueue = (state, { payload }) =>
  update(state, {
    queue: { $set: difference(state.queue, [payload]) },
  });

const mergeQueue = (state, { payload }) =>
  update(state, {
    queue: {
      $set: union(state.queue, difference(payload.reviewIds, [state.current.id], state.complete)),
    },
{'fraction_non_alphanumeric': 0.17229977957384277, 'fraction_numerical': 0.002571638501102131, 'mean_word_length': 3.4704433497536944, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 29, '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': '7575812', 'n_tokens_mistral': 1816, 'n_tokens_neox': 1793, 'n_words': 401}