{"size": 1383, "ext": "js", "max_stars_repo_path": "family-tree-maker/src/reducers/manageRelatives.js", "max_stars_repo_name": "Never2Far/family-tree-maker-v3", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "family-tree-maker/src/reducers/manageRelatives.js", "max_issues_repo_name": "Never2Far/family-tree-maker-v3", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "family-tree-maker/src/reducers/manageRelatives.js", "max_forks_repo_name": "Never2Far/family-tree-maker-v3", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 28.2244897959, "max_line_length": 150, "alphanum_fraction": 0.5849602314}
function manageRelatives(state = {relatives: [],
                                loading: false}, action)  {

switch (action.type) {
    case 'ADDING_RELATIVE':
        console.log('Adding Relative to DB....')

        return Object.assign({}, {relatives: [...state.relatives]}, {loading: true})

    case 'DELETING_RELATIVE':
        console.log('Removing Relative from DB....')

        return Object.assign({}, {relatives: [...state.relatives]}, {loading: true})

    case 'FETCHING_RELATIVES':
        console.log('Fetching saved relatives from DB....')
    
        return Object.assign({}, {relatives: [...state.relatives]}, {loading: true})

    case 'UPDATING_RELATIVE':
        console.log('Updating relative...')
    
        return Object.assign({}, {relatives: [...state.relatives]}, {loading: true})

    case 'ADD_RELATIVE':
        
        const relative = action.payload
        if (!state.relatives.includes(relative)) {
        
        return Object.assign({}, {relatives: [...state.relatives, relative]}, {loading: false})
        }
            
        else {
            return state
        }
        
    case 'REMOVE_RELATIVE':

        return Object.assign({}, {relatives: state.relatives.filter(relative => relative.relativeId !== action.payload.relativeId)}, {loading: false})

    
    default:
        return state
}

}

export default manageRelatives
