email: {
folderList: [ {
name: 'Inbox',
isSelected: false,
isNested: true,
visible: false,
folderList: [ {
name: 'SubFolder1',
isNested: true,
visible: false,
folderList : [ {
name: 'SubFolder2',
isNested: true,
visible: false,
folderList: [ {
name: 'SubFolder3',
isNested: false,
visible: false
} ],
count: 5
} ]
}, {
name: 'SubFolder1',
isNested: false,
visible: false
} ]
}
folders: {
'123': {
id: 123,
name: 'Inbox',
isSelected: false,
parentId: 123,
visible: false,
},
}
function folder(action, state = initialState) {
switch(action.type) {
case OPEN_FOLDER_ACTION:
const nextFolders = _.mapValues(state.folders, folder => {
// Устанавливаем флаг "выбрана" для выбранной папки
if (folder.id === action.targetId) {
return { ...folder, isSelected: true };
}
// Для дочерних папок устанавливаем флаг видимости
if (folder.parentId === action.targetId) {
return { ...folder, visible: true };
}
return folder;
});
return {
...state,
folders: { ...nextFolders },
};
// ...
}
}