import { USER_PLAYLIST_CONSTANTS } from '../actions/user';

const initialState = {
	playlists: {
		totalCount: 0,
		nextOffset: 0
	}
};

export default function apiMeta(state = initialState, action){
	switch(action.type){
		case USER_PLAYLIST_CONSTANTS.SUCCESS:
			let data = action.data;
  			let offsetMatch = /offset=(\d+)/.exec(data.next);
  			let nextRequestOffset = offsetMatch ? offsetMatch[1] : 0;
			return Object.assign({}, state, {
				playlists: {
					totalCount: data.total,
					nextOffset: nextRequestOffset
				}
			});
		default:
			return state;
	}
}
@@ -1,8 +1,32 @@
+import _ from 'lodash';%0A
 import %7B
@@ -53,34 +53,333 @@
 ANTS
- %7D from '../actions/user';
+, PLAYLIST_TRACKS_CONSTANTS %7D from '../actions/user';%0A%0Afunction calculateApiPagination(newState, action)%7B%0A%09let data = action.data;%0A  %09let offsetMatch = /offset=(%5Cd+)/.exec(data.next);%0A  %09let nextRequestOffset = offsetMatch ? offsetMatch%5B1%5D : 0;%0A  %09return %7B%0A  %09%09totalCount: data.total,%0A  %09%09nextOffset: nextRequestOffset%0A  %09%7D%0A%7D
 %0A%0Aco
@@ -452,11 +452,31 @@
 0%0A%09%7D
+,%0A%09playlistTracks: %7B%7D
 %0A%7D
-;
 %0A%0Aex
@@ -536,16 +536,58 @@
 ction)%7B%0A
+%09let newState = Object.assign(%7B%7D, state);%0A
 %09switch(
@@ -647,280 +647,310 @@
 %0A%09%09%09
-let data = action.data;%0A  %09%09%09let offsetMatch = /offset=(%5Cd+)/.exec(data.next);%0A  %09%09%09let nextRequestOffset = offsetMatch ? offsetMatch%5B1%5D : 0;%0A%09%09%09return Object.assign(%7B%7D, state, %7B%0A%09%09%09%09playlists: %7B%0A%09%09%09%09%09totalCount: data.total,%0A%09%09%09%09%09nextOffset: nextRequestOffset%0A%09%09%09%09%7D%0A%09%09%09%7D);
+return _.merge(newState, %7B%0A%09%09%09%09playlists: calculateApiPagination(newState, action)%0A%09%09%09%7D);%0A%09%09case PLAYLIST_TRACKS_CONSTANTS.SUCCESS:%0A%09%09%09let playlistsTracks = %7BplaylistsTracks: %7B%7D%7D;%0A%09%09%09playlistTracks%5Bdata.playlistId%5D = calculateApiPagination(newState, action);%0A%09%09%09return _.merge(newState, playlistTracks)
 %0A%09%09d

Add apiMeta for playlist tracks