{"size": 796, "ext": "js", "max_stars_repo_path": "client/src/reducers/author.js", "max_stars_repo_name": "RenatoPaulic/AuthorsDemoApp", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "client/src/reducers/author.js", "max_issues_repo_name": "RenatoPaulic/AuthorsDemoApp", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "client/src/reducers/author.js", "max_forks_repo_name": "RenatoPaulic/AuthorsDemoApp", "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": 23.4117647059, "max_line_length": 86, "alphanum_fraction": 0.5025125628}
import { GET_ALL_BOOKS, BOOK_OPERATION, BOOK_OPERATION_ERROR } from '../actions/types'

const initialState = {
    books: [],
    loading: true
}

function authorReducer(state = initialState, action) {

    const {type, payload} = action

    switch(type){
        case GET_ALL_BOOKS:
           return { 
               books: payload, 
               loading: false
            } 
        case BOOK_OPERATION:
            return { 
                ...state, 
                loading: true 
            }
        case BOOK_OPERATION_ERROR:
            console.error(`Error - ${type}: ${payload.status}, ${payload.msg}`)
            return { 
                ...state, 
                loading: false 
            }
        default: 
            return state
    }
}

export default authorReducer