2020-12-16 00:31:30 +00:00
|
|
|
import {
|
2020-12-17 06:34:00 +00:00
|
|
|
ALBUMS_FETCH_REQUEST,
|
|
|
|
ALBUMS_FETCH_SUCCESS,
|
|
|
|
ALBUMS_FETCH_FAIL,
|
2020-12-22 17:11:22 +00:00
|
|
|
ALBUM_CREATE_SUCCESS,
|
|
|
|
ALBUM_REMOVE_REQUEST,
|
2020-12-18 04:46:37 +00:00
|
|
|
} from '../actions/albums'
|
2020-12-16 00:31:30 +00:00
|
|
|
import { Map as ImmutableMap, List as ImmutableList, fromJS } from 'immutable'
|
|
|
|
|
2020-12-22 17:11:22 +00:00
|
|
|
const importAlbum = (state, album) => state.set(album.id, fromJS(album))
|
|
|
|
|
|
|
|
const importAlbums = (state, albums) =>
|
|
|
|
state.withMutations((mutable) => albums.forEach((album) => importAlbum(mutable, album)))
|
|
|
|
|
|
|
|
const initialState = ImmutableMap()
|
2020-12-16 00:31:30 +00:00
|
|
|
|
|
|
|
export default function albums(state = initialState, action) {
|
|
|
|
switch(action.type) {
|
2020-12-17 06:34:00 +00:00
|
|
|
case ALBUMS_FETCH_SUCCESS:
|
2020-12-22 17:11:22 +00:00
|
|
|
return importAlbums(state, action.albums)
|
|
|
|
case ALBUM_CREATE_SUCCESS:
|
|
|
|
return importAlbum(state, action.album)
|
|
|
|
case ALBUM_REMOVE_REQUEST:
|
|
|
|
return state.delete(action.albumId)
|
2020-12-16 00:31:30 +00:00
|
|
|
default:
|
|
|
|
return state
|
|
|
|
}
|
|
|
|
}
|