<commit_before>import _ from 'lodash'

const initialState = {
      selectedBoard: 1,
      boardsPanelOpen: false,
      boards: [
        {
          boardId: 1,
          boardIndex: 1,
          boardTitle: 'my board',
          lists: [
            {
              listId: 1,
              listIndex: 1,
              listTitle: 'To Do',
              items: [
                {
                  itemId: 1,
                  itemIndex: 1,
                  itemText: 'test'
                }
              ]
            }
          ]
        },
        {
          boardId: 2,
          boardIndex: 3,
          boardTitle: 'my board 2',
          lists: [
            {
              listId: 1,
              listIndex: 1,
              listTitle: 'To Do 2',
              items: [
                {
                  itemId: 1,
                  itemIndex: 1,
                  itemText: 'test 2'
                }
              ]
            }
          ]
        }
      ]
    }


export default function reducer(state =initialState, action){


	switch(action.type){
    case 'TOGGLE_BOARDS_PANEL': {
      console.log(state.boardsPanelOpen)
      console.log(!state.boardsPanelOpen)

      return {...state, boardsPanelOpen:!state.boardsPanelOpen}
      break
    }
    case 'CREATE_ITEM':{
      let {boardId, listId, itemText} = action.payload
      let newState = _.cloneDeep(state)
      let items = newState.boards.find(board => {return board.boardId === boardId}).lists.find(list => {return list.listId === listId}).items
      items.push({itemText,itemId: _.random(10000), itemIndex: items.length+1})
      return newState
      break
    }
    case 'DELETE_ITEM': {
      let {boardId, listId, itemId} = action.payload
      let newState = _.cloneDeep(state)
      let items = newState.boards.find(board => {return board.boardId === boardId}).lists.find(list => {return list.listId === listId}).items
      let index = items.findIndex(item => item.itemId === itemId)
      items.splice(index,1)
      return newState
      break

    }
    case 'CREATE_LIST':{
      let {boardId, listTitle} = action.payload
      let newState = _.cloneDeep(state)
      const lists = newState.boards.find(board => {return board.boardId === boardId}).lists
      lists.push({listId: _.random(100000), listIndex:lists.length+1,listTitle, items:[]})
      return newState
      break
    }
    case 'DELETE_LIST': {
      let {boardId, listId} = action.payload
      let newState = _.cloneDeep(state)
      const lists = newState.boards.find(board => {return board.boardId === boardId}).lists
      let index = lists.findIndex(list => list.listId === listId)
      lists.splice(index,1)
      return newState
      break

    }
    case 'SELECT_BOARD': {
      return {...state, selectedBoard: action.payload.boardId, boardsPanelOpen:false}
    }
    case 'CREATE_BOARD': {
      let {boardTitle} = action.payload
      let newState = _.cloneDeep(state)
      const boardId = _.random(1000)
      newState.boards.push({boardId:boardId , boardIndex:newState.boards.length+1, boardTitle, lists:[]})
      newState.selectedBoard = boardId
      newState.boardsPanelOpen = false
      return newState
    }
    case 'DELETE_BOARD': {
      let {boardId} = action.payload
      let newState = _.cloneDeep(state)
      let index = newState.boards.findIndex(board => board.boardId === boardId)
      newState.boards.splice(index,1)
      return newState
    }
    case 'SWAP_LISTS': {
      let {boardId, dragListId, hoverListId} = action.payload
      let newState = _.cloneDeep(state)
      let board = _.find(newState.boards, (o) => o.boardId === boardId)
      let dragList = _.find(board.lists, (o) => o.listId === dragListId)
      let hoverList = _.find(board.lists, (o) => o.listId === hoverListId)
      let dragIndex = dragList.listIndex
      let hoverIndex = hoverList.listIndex
      dragList.listIndex = hoverIndex
      hoverList.listIndex = dragIndex
      return newState
    }
    case 'SWAP_ITEMS': {
      let {boardId, dragListId, dragItemId, hoverItemId} = action.payload
      let newState = _.cloneDeep(state)
      let board = _.find(newState.boards, (o) => o.boardId === boardId)
      let dragList = _.find(board.lists, (o) => o.listId === dragListId)
      let dragItem = _.find(dragList.items, (o) => o.itemId === dragItemId)
      let hoverItem = _.find(dragList.items, (o) => o.itemId === hoverItemId)
      let dragIndex = dragItem.itemIndex
      let hoverIndex = hoverItem.itemIndex
      dragItem.itemIndex = hoverIndex
      hoverItem.itemIndex = dragIndex
      return newState
    }

    case 'MOVE_ITEM_TO_LIST': {
      let {boardId, dragListId, hoverListId, dragItemId} = action.payload
      let newState = _.cloneDeep(state)
      let board = _.find(newState.boards, (o) => o.boardId === boardId)
      let dragList = _.find(board.lists, (o) => o.listId === dragListId)
      let hoverList = _.find(board.lists, (o) => o.listId === hoverListId)
      let dragItem = _.find(dragList.items, (o) => o.itemId === dragItemId)
      dragItem.itemIndex = hoverList.items.length+1
      hoverList.items.push(dragItem)
      dragList.items = dragList.items.filter((o) => o.itemId !== dragItemId)

      return newState
    }

		default:
			return state;
	}
}
<commit_msg>fixed IE compatibility with find and findIndex<commit_after>import _ from 'lodash'

const initialState = {
      selectedBoard: 1,
      boardsPanelOpen: false,
      boards: [
        {
          boardId: 1,
          boardIndex: 1,
          boardTitle: 'my board',
          lists: [
            {
              listId: 1,
              listIndex: 1,
              listTitle: 'To Do',
              items: [
                {
                  itemId: 1,
                  itemIndex: 1,
                  itemText: 'test'
                }
              ]
            }
          ]
        },
        {
          boardId: 2,
          boardIndex: 3,
          boardTitle: 'my board 2',
          lists: [
            {
              listId: 1,
              listIndex: 1,
              listTitle: 'To Do 2',
              items: [
                {
                  itemId: 1,
                  itemIndex: 1,
                  itemText: 'test 2'
                }
              ]
            }
          ]
        }
      ]
    }


export default function reducer(state =initialState, action){
//   if (!Array.prototype.find) {
//   Array.prototype.find = function(predicate) {
//     'use strict';
//     if (this == null) {
//       throw new TypeError('Array.prototype.find called on null or undefined');
//     }
//     if (typeof predicate !== 'function') {
//       throw new TypeError('predicate must be a function');
//     }
//     var list = Object(this);
//     var length = list.length >>> 0;
//     var thisArg = arguments[1];
//     var value;

//     for (var i = 0; i < length; i++) {
//       value = list[i];
//       if (predicate.call(thisArg, value, i, list)) {
//         return value;
//       }
//     }
//     return undefined;
//   };
// }


	switch(action.type){
    case 'TOGGLE_BOARDS_PANEL': {

      return {...state, boardsPanelOpen:!state.boardsPanelOpen}
      break
    }
    case 'CREATE_ITEM':{
      let {boardId, listId, itemText} = action.payload
      let newState = _.cloneDeep(state)
      let board = _.find(newState.boards, (board) => board.boardId === boardId)
      let items = _.find(board.lists, (list) => list.listId === listId).items
      items.push({itemText,itemId: _.random(10000), itemIndex: items.length+1})
      return newState
      break
    }
    case 'DELETE_ITEM': {
      let {boardId, listId, itemId} = action.payload
      let newState = _.cloneDeep(state)
      let board = _.find(newState.boards, (board) => board.boardId === boardId)
      let items = _.find(board.lists, (list) => list.listId === listId).items
      let index = _.findIndex(items, (item) => item.itemId === itemId)
      items.splice(index,1)
      return newState
      break

    }
    case 'CREATE_LIST':{
      let {boardId, listTitle} = action.payload
      let newState = _.cloneDeep(state)
      const lists = _.find(newState.boards, (board) => board.boardId === boardId).lists
      lists.push({listId: _.random(100000), listIndex:lists.length+1,listTitle, items:[]})
      return newState
      break
    }
    case 'DELETE_LIST': {
      let {boardId, listId} = action.payload
      let newState = _.cloneDeep(state)
      const lists = _.find(newState.boards, (board) => board.boardId === boardId).lists
      let index = _.findIndex(lists, (list) => list.listId === listId)
      lists.splice(index,1)
      return newState
      break

    }
    case 'SELECT_BOARD': {
      return {...state, selectedBoard: action.payload.boardId, boardsPanelOpen:false}
    }
    case 'CREATE_BOARD': {
      let {boardTitle} = action.payload
      let newState = _.cloneDeep(state)
      const boardId = _.random(1000)
      newState.boards.push({boardId:boardId , boardIndex:newState.boards.length+1, boardTitle, lists:[]})
      newState.selectedBoard = boardId
      newState.boardsPanelOpen = false
      return newState
    }
    case 'DELETE_BOARD': {
      let {boardId} = action.payload
      let newState = _.cloneDeep(state)
      let index = _.findIndex(newState.boards, (board) => board.boardId === boardId)
      newState.boards.splice(index,1)
      return newState
    }
    case 'SWAP_LISTS': {
      let {boardId, dragListId, hoverListId} = action.payload
      let newState = _.cloneDeep(state)
      let board = _.find(newState.boards, (o) => o.boardId === boardId)
      let dragList = _.find(board.lists, (o) => o.listId === dragListId)
      let hoverList = _.find(board.lists, (o) => o.listId === hoverListId)
      let dragIndex = dragList.listIndex
      let hoverIndex = hoverList.listIndex
      dragList.listIndex = hoverIndex
      hoverList.listIndex = dragIndex
      return newState
    }
    case 'SWAP_ITEMS': {
      let {boardId, dragListId, dragItemId, hoverItemId} = action.payload
      let newState = _.cloneDeep(state)
      let board = _.find(newState.boards, (o) => o.boardId === boardId)
      let dragList = _.find(board.lists, (o) => o.listId === dragListId)
      let dragItem = _.find(dragList.items, (o) => o.itemId === dragItemId)
      let hoverItem = _.find(dragList.items, (o) => o.itemId === hoverItemId)
      let dragIndex = dragItem.itemIndex
      let hoverIndex = hoverItem.itemIndex
      dragItem.itemIndex = hoverIndex
      hoverItem.itemIndex = dragIndex
      return newState
    }

    case 'MOVE_ITEM_TO_LIST': {
      let {boardId, dragListId, hoverListId, dragItemId} = action.payload
      let newState = _.cloneDeep(state)
      let board = _.find(newState.boards, (o) => o.boardId === boardId)
      let dragList = _.find(board.lists, (o) => o.listId === dragListId)
      let hoverList = _.find(board.lists, (o) => o.listId === hoverListId)
      let dragItem = _.find(dragList.items, (o) => o.itemId === dragItemId)
      dragItem.itemIndex = hoverList.items.length+1
      hoverList.items.push(dragItem)
      dragList.items = dragList.items.filter((o) => o.itemId !== dragItemId)

      return newState
    }

		default:
			return state;
	}
}

{'fraction_non_alphanumeric': 0.12647659650057733, 'fraction_numerical': 0.007016608935074163, 'mean_word_length': 2.0976616231086656, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 48, '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': '5070535', 'n_tokens_mistral': 3533, 'n_tokens_neox': 3429, 'n_words': 771}