import {
    RECEIVE_MY_COURSES,
    SWITCH_TAB,
    NOMORE_COURSE
} from './actions'

const initialState = {
    switchTab: false,
    courseList: [],
    page: 0,
    statusCode: 0,
    msg: '',
    noMore: false,
}


export default function myCourses(state = initialState, action) {
    switch (action.type) {
        case RECEIVE_MY_COURSES:
            let {courseList, ...rest} = action.payload
            return {
                ...state, ...rest,
                courseList: Object.keys(courseList).length === 0 ? state.courseList : state.courseList.concat(courseList)
            }
        case SWITCH_TAB:
            return {...state, switchTab: action.payload}
        case NOMORE_COURSE:
            return {...state, noMore: true}
        default:
            return state
    }
}