import { fromJS } from 'immutable';
import {
  SEARCH_REQUEST,
  SEARCH_SUCCESS,
  SEARCH_ERROR,
  SELECT_BOOK,
  UNSELECT_BOOK,
} from './constants';

const initialState = fromJS({
  searching: false,
  error: false,
  books: false,
  activeBook: false,
});

function addBookPageReducer(state = initialState, action) {
  switch (action.type) {
    case SEARCH_REQUEST:
      return state
        .set('error', false)
        .set('books', false)
        .set('activeBook', false)
        .set('searching', true);
    case SEARCH_SUCCESS:
      return state
        .set('searching', false)
        .set('books', action.payload.books);
    case SEARCH_ERROR:
      return state
        .set('searching', false)
        .set('error', action.payload.error);
    case SELECT_BOOK:
      return state
        .set('activeBook', action.payload.book);
    case UNSELECT_BOOK:
      return state
        .set('activeBook', false);
    default:
      return state;
  }
}

export default addBookPageReducer;

@@ -122,16 +122,36 @@
 T_BOOK,%0A
+  ADD_BOOK_SUCCESS,%0A
 %7D from '
@@ -933,24 +933,196 @@
 k', false);%0A
+    case ADD_BOOK_SUCCESS:%0A      return state%0A        .set('error', false)%0A        .set('books', false)%0A        .set('activeBook', false)%0A        .set('searching', false);%0A
     default:

Reset state on book added