import {SELECT_ARTIST, UNSELECT_ARTIST, SELECT_ALBUM, UNSELECT_ALBUM } from '../actions/actionKeys';


const defaultState = {
    artist: {},
    album: {}
};

const selection = (state = defaultState, action) => {
    switch (action.type) {
        case SELECT_ARTIST:
            if(!state.artist || state.artist.index !== action.index) {
                return Object.assign({}, state, {
                    artist: {
                        index: action.index,
                        name: action.name
                    }
                });
            }
            break;

        case UNSELECT_ARTIST:
            return defaultState;

        case SELECT_ALBUM:
            return Object.assign({}, state, {
                album: {
                    index: action.index,
                    name: action.name
                }
            });

        case UNSELECT_ALBUM:
            return {
                ...state,
                album: {}
            };
    }
    return state;
};

export const getArtist = (state) => {
    return state && state.artist;
};

export const getAlbum = (state) => {
    return state && state.album;
};

export default selection;

@@ -359,36 +359,11 @@
 turn
- Object.assign(%7B%7D, state,
  %7B%0A
+
     
@@ -488,32 +488,33 @@
                %7D
+,
 %0A               
@@ -514,18 +514,47 @@
         
+    album: %7B%7D%0A                
 %7D
-)
 ;%0A      
@@ -695,34 +695,35 @@
 urn 
-Object.assign(%7B%7D, 
+%7B%0A                ...
 state,
- %7B
 %0A   
@@ -833,32 +833,32 @@
               %7D%0A
+
             %7D);%0A
@@ -854,17 +854,16 @@
        %7D
-)
 ;%0A%0A     

reset album if artist has changed