<commit_before>import { fromJS } from 'immutable';

import {
  INVALIDATE_CONTAINER,
  BEGIN_FETCHING_CONTAINER,
  FINISH_FETCHING_CONTAINER,
  FAIL_FETCHING_CONTAINER } from '../actions/container-actions';
import { ADD_CARD, REMOVE_CARD } from '../actions/card-actions';

const containerInitialState = (initialCardsData = []) => ({
  isFetching: false,
  lastSaved: undefined,
  error: undefined,
  data: {
    cards: initialCardsData,
  },
});

const containersInitialState = fromJS({
  deckbuilder: containerInitialState({}),
  library: containerInitialState(),
  search: containerInitialState(),
});

const containerReducer = (state = containersInitialState, action) => {
  switch (action.type) {
    case BEGIN_FETCHING_CONTAINER:
      return state.update(action.payload, container => (
        container.set('isFetching', true)
          .set('error', undefined)
      ));

    case FINISH_FETCHING_CONTAINER:
      return state.update(action.payload.container, container => (
        container.set('isFetching', false)
          .update('data', data => data
            .set(action.payload.entityType, fromJS(action.payload.entityIds))
          )
      ));

    case FAIL_FETCHING_CONTAINER:
      return state.update(action.payload.container, container => (
        container.set('isFetching', false)
          .set('error', action.error)
        ));

    case ADD_CARD:
    console.log('ADD_CARD');
      return state.update(action.payload.container, container => (
        container.update('data', data => data
          .update('cards', cards => {
            console.log(cards.get(action.payload.id));
            console.log(cards.update(action.payload.id, value => value + action.payload.amount));
            if (cards.get(action.payload.id)) {
              return cards.update(action.payload.id, value => value + action.payload.amount);
            } else {
              return cards.set(action.payload.id, action.payload.amount);
            }
          }))
      ));

    case REMOVE_CARD:
      return state.update(action.payload.container, container => (
        container.update('data', data => data
          .update('cards', cards => {
            const newAmount = cards.get(action.payload.id) - action.payload.amount
            if (newAmount > 0) {
              return cards.update(action.payload.id, newAmount);
            } else {
              return cards.remove(action.payload.id);
            }
          }))
      ));

    default: return state;<commit_msg>Fix wrong method called in container reducer<commit_after>import { fromJS } from 'immutable';

import {
  INVALIDATE_CONTAINER,
  BEGIN_FETCHING_CONTAINER,
  FINISH_FETCHING_CONTAINER,
  FAIL_FETCHING_CONTAINER } from '../actions/container-actions';
import { ADD_CARD, REMOVE_CARD } from '../actions/card-actions';

const containerInitialState = (initialCardsData = []) => ({
  isFetching: false,
  lastSaved: undefined,
  error: undefined,
  data: {
    cards: initialCardsData,
  },
});

const containersInitialState = fromJS({
  deckbuilder: containerInitialState({}),
  library: containerInitialState(),
  search: containerInitialState(),
});

const containerReducer = (state = containersInitialState, action) => {
  switch (action.type) {
    case BEGIN_FETCHING_CONTAINER:
      return state.update(action.payload, container => (
        container.set('isFetching', true)
          .set('error', undefined)
      ));

    case FINISH_FETCHING_CONTAINER:
      return state.update(action.payload.container, container => (
        container.set('isFetching', false)
          .update('data', data => data
            .set(action.payload.entityType, fromJS(action.payload.entityIds))
          )
      ));

    case FAIL_FETCHING_CONTAINER:
      return state.update(action.payload.container, container => (
        container.set('isFetching', false)
          .set('error', action.error)
        ));

    case ADD_CARD:
    console.log('ADD_CARD');
      return state.update(action.payload.container, container => (
        container.update('data', data => data
          .update('cards', cards => {
            console.log(cards.get(action.payload.id));
            console.log(cards.update(action.payload.id, value => value + action.payload.amount));
            if (cards.get(action.payload.id)) {
              return cards.update(action.payload.id, value => value + action.payload.amount);
            } else {
              return cards.set(action.payload.id, action.payload.amount);
            }
          }))
      ));

    case REMOVE_CARD:
      return state.update(action.payload.container, container => (
        container.update('data', data => data
          .update('cards', cards => {
            const newAmount = cards.get(action.payload.id) - action.payload.amount
            if (newAmount > 0) {
              return cards.set(action.payload.id, newAmount);
            } else {
              return cards.remove(action.payload.id);
            }
          }))
      ));

    default: return state;
{'fraction_non_alphanumeric': 0.1298804780876494, 'fraction_numerical': 0.00039840637450199205, 'mean_word_length': 2.6252707581227437, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 33, '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': '6426254', 'n_tokens_mistral': 1474, 'n_tokens_neox': 1426, 'n_words': 259}