<commit_before>import _ from 'lodash';
import { Constants as PackageConstants } from '../actions/scorm';

const initialState = {
  scormList: null,
  loadError: false,
  uploadError: false,
  shouldRefreshList: false,
  listAssignmentsDone: false,
  canvasAssignments: null,
  file: null,
};

export default (state = initialState, action) => {
  switch (action.type) {

    case 'CREATE_ASSIGNMENT': {
      const updatedScorm = { ...state.scormList[action.localData.index] };
      updatedScorm.fetching = true;
      const updatedScormList = state.scormList.slice();
      updatedScormList[action.localData.index] = updatedScorm;
      return { ...state, scormList: updatedScormList };
    }
    case 'EDIT_ASSIGNMENT': {
      const newState = _.cloneDeep(state);
      newState
        .canvasAssignments[action.params.id]
        .published = action.body.assignment.published;
      return { ...newState };
    }
    case 'CREATE_ASSIGNMENT_DONE': {
      const updatedScorm = { ...state.scormList[action.original.localData.index] };
      updatedScorm.fetching = false;
      const updatedScormList = state.scormList.slice();
      updatedScormList[action.original.localData.index] = updatedScorm;
      const updatedAssignments = state.canvasAssignments;
      updatedAssignments[action.payload.id] = action.payload;
      return { ...state, scormList: updatedScormList, canvasAssignments: updatedAssignments };
    }
    case 'LIST_ASSIGNMENTS_DONE': {
      const newState = _.cloneDeep(state);
      const updatedAssignments = newState.canvasAssignments;
      if (!updatedAssignments) newState.canvasAssignments = {};
      _.forEach(action.payload, (assignment) => {
        newState.canvasAssignments[assignment.id] = assignment;
      });
      return { ...newState, listAssignmentsDone: action.lastPage };
    }
    case PackageConstants.UPDATE_IMPORT_TYPE: {
      const updatedScorm = { ...state.scormList[action.index] };
      updatedScorm.is_graded = action.importType;
      const updatedScormList = state.scormList.slice();
      updatedScormList[action.index] = updatedScorm;
      return { ...state, scormList: updatedScormList };
    }
    case PackageConstants.LOAD_PACKAGES_DONE:
      if (action.error) {
        return { ...state, loadError: true };
      }
      return {
        ...state,
        scormList: _.map(action.payload.response, (item, index) => ({ ...item, index })),
        shouldRefreshList: false,
        file: null,
      };

    case PackageConstants.UPLOAD_PACKAGE: {
      const file = action.upload;
      const showUpload = true;
      return { ...state, showUploading: showUpload, file };
    }
    case PackageConstants.REMOVE_PACKAGE: {
      const newState = _.cloneDeep(state);
      _.remove(newState.scormList, scorm => scorm.id === action.courseId);
      return newState;
    }

    case PackageConstants.REMOVE_PACKAGE_DONE:
    case PackageConstants.UPLOAD_PACKAGE_DONE: {
      if (action.error) {
        return {
          ...state,
          file: action.original.upload,
          uploadError: true,
          errorText: action.error.rawResponse,
        };
      }
      return { ...state, file: null, shouldRefreshList: true };
    }
    case PackageConstants.UPDATE_UPLOAD_FILE:
      return { ...state, file: action.file };

    case PackageConstants.REMOVE_ERROR:
      return { ...state, file: null, uploadError: false };

    case PackageConstants.REPLACE_PACKAGE: {
      const updatedPackage = { ...state.scormList[action.params.index] };
      updatedPackage.fetching = true;
      const updatedScormList = state.scormList.slice();
      updatedScormList[action.params.index] = updatedPackage;
      return { ...state, scormList: updatedScormList };
    }

    case PackageConstants.REPLACE_PACKAGE_DONE:
      return { ...state, shouldRefreshList: true };

    default:
      return state;
  }
};
<commit_msg>Should take care of UI issue<commit_after>import _ from 'lodash';
import { Constants as PackageConstants } from '../actions/scorm';

const initialState = {
  scormList: null,
  loadError: false,
  uploadError: false,
  shouldRefreshList: false,
  listAssignmentsDone: false,
  canvasAssignments: null,
  file: null,
};

export default (state = initialState, action) => {
  switch (action.type) {

    case 'CREATE_ASSIGNMENT': {
      const updatedScorm = { ...state.scormList[action.localData.index] };
      updatedScorm.fetching = true;
      const updatedScormList = state.scormList.slice();
      updatedScormList[action.localData.index] = updatedScorm;
      return { ...state, scormList: updatedScormList };
    }
    case 'EDIT_ASSIGNMENT': {
      const newState = _.cloneDeep(state);
      newState
        .canvasAssignments[action.params.id]
        .published = action.body.assignment.published;
      return { ...newState };
    }
    case 'CREATE_ASSIGNMENT_DONE': {
      const updatedScorm = { ...state.scormList[action.original.localData.index] };
      const updatedScormList = state.scormList.slice();
      updatedScormList[action.original.localData.index] = updatedScorm;
      const updatedAssignments = state.canvasAssignments;
      updatedAssignments[action.payload.id] = action.payload;
      return { ...state, scormList: updatedScormList, canvasAssignments: updatedAssignments };
    }
    case 'LIST_ASSIGNMENTS_DONE': {
      const newState = _.cloneDeep(state);
      const updatedAssignments = newState.canvasAssignments;
      if (!updatedAssignments) newState.canvasAssignments = {};
      _.forEach(action.payload, (assignment) => {
        newState.canvasAssignments[assignment.id] = assignment;
      });
      return { ...newState, listAssignmentsDone: action.lastPage };
    }
    case PackageConstants.UPDATE_IMPORT_TYPE: {
      const updatedScorm = { ...state.scormList[action.index] };
      updatedScorm.is_graded = action.importType;
      const updatedScormList = state.scormList.slice();
      updatedScormList[action.index] = updatedScorm;
      return { ...state, scormList: updatedScormList };
    }
    case PackageConstants.LOAD_PACKAGES_DONE:
      if (action.error) {
        return { ...state, loadError: true };
      }
      return {
        ...state,
        scormList: _.map(action.payload.response, (item, index) => ({ ...item, index })),
        shouldRefreshList: false,
        file: null,
      };

    case PackageConstants.UPLOAD_PACKAGE: {
      const file = action.upload;
      const showUpload = true;
      return { ...state, showUploading: showUpload, file };
    }
    case PackageConstants.REMOVE_PACKAGE: {
      const newState = _.cloneDeep(state);
      _.remove(newState.scormList, scorm => scorm.id === action.courseId);
      return newState;
    }

    case PackageConstants.REMOVE_PACKAGE_DONE:
    case PackageConstants.UPLOAD_PACKAGE_DONE: {
      if (action.error) {
        return {
          ...state,
          file: action.original.upload,
          uploadError: true,
          errorText: action.error.rawResponse,
        };
      }
      return { ...state, file: null, shouldRefreshList: true };
    }
    case PackageConstants.UPDATE_UPLOAD_FILE:
      return { ...state, file: action.file };

    case PackageConstants.REMOVE_ERROR:
      return { ...state, file: null, uploadError: false };

    case PackageConstants.REPLACE_PACKAGE: {
      const updatedPackage = { ...state.scormList[action.params.index] };
      updatedPackage.fetching = true;
      const updatedScormList = state.scormList.slice();
      updatedScormList[action.params.index] = updatedPackage;
      return { ...state, scormList: updatedScormList };
    }

    case PackageConstants.REPLACE_PACKAGE_DONE:
      return { ...state, shouldRefreshList: true };

    default:
      return state;
  }
};

{'fraction_non_alphanumeric': 0.1166838576585869, 'fraction_numerical': 0.0, 'mean_word_length': 2.8940763052208833, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 11, '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': '4105063', 'n_tokens_mistral': 2281, 'n_tokens_neox': 2274, 'n_words': 443}