import {
  REQUEST_SELECTIONS, RECEIVE_SELECTIONS_SUCCESS, RECEIVE_SELECTIONS_ERROR,
} from '../actions';

export function selections (state = {
  isFetching: false,
  items: {},
}, action) {
  switch (action.type) {
  case REQUEST_SELECTIONS:
    return Object.assign({}, state, {
      isFetching: true,
    });

  case RECEIVE_SELECTIONS_SUCCESS:
    return Object.assign({}, state, {
      isFetching: false,
      items: action.items.reduce((obj, item) => {
        obj[item._id] = item; // eslint-disable-line no-param-reassign
        return obj;
      }, {}),
    });

  case RECEIVE_SELECTIONS_ERROR:
    return Object.assign({}, state, {
      isFetching: false,
    });

  default:
    return state;
  }
}

@@ -78,16 +78,86 @@
 _ERROR,%0A
+  CREATE_SELECTION, CREATE_SELECTION_SUCCESS, CREATE_SELECTION_ERROR,%0A
 %7D from '
@@ -255,16 +255,30 @@
 tion) %7B%0A
+  let items;%0A%0A
   switch
@@ -746,24 +746,24 @@
 ing: false,%0A
-
     %7D);%0A%0A  d
@@ -759,16 +759,603 @@
    %7D);%0A%0A
+  case CREATE_SELECTION:%0A    items = Object.assign(%7B%7D, state.items);%0A    items%5Baction.selection._id%5D = action.selection;%0A    return Object.assign(%7B%7D, state, %7B%0A      isFetching: true,%0A      items,%0A    %7D);%0A%0A  case CREATE_SELECTION_SUCCESS:%0A    items = Object.assign(%7B%7D, state.items);%0A    delete items%5Baction._id%5D;%0A    items%5Baction.selection._id%5D = action.selection;%0A    return %7B%0A      isFetching: false,%0A      items,%0A    %7D;%0A%0A  case CREATE_SELECTION_ERROR:%0A    items = Object.assign(%7B%7D, state.items);%0A    delete items%5Baction._id%5D;%0A    return %7B%0A      isFetching: false,%0A      items,%0A    %7D;%0A%0A
   defaul

Handle selection creation actions