reducers.js 964 Bytes
Newer Older
zhanghaozhe committed
1 2
import {
    RECEIVE_MY_COURSES,
zhanghaozhe committed
3
    SWITCH_TAB,
zhanghaozhe committed
4 5
    NOMORE_COURSE,
    START_FETCHING_COURSES
zhanghaozhe committed
6
} from './actions'
zhanghaozhe committed
7 8

const initialState = {
zhanghaozhe committed
9
    switchTab: false,
zhanghaozhe committed
10
    courseList: [],
zhanghaozhe committed
11
    page: 0,
zhanghaozhe committed
12 13
    statusCode: 0,
    msg: '',
zhanghaozhe committed
14
    noMore: false,
zhanghaozhe committed
15
    isLoading: true
zhanghaozhe committed
16 17 18 19 20 21
}


export default function myCourses(state = initialState, action) {
    switch (action.type) {
        case RECEIVE_MY_COURSES:
zhanghaozhe committed
22
            let {courseList, ...rest} = action.payload
zhanghaozhe committed
23 24
            return {
                ...state, ...rest,
zhanghaozhe committed
25 26
                courseList: Object.keys(courseList).length === 0 ? state.courseList : state.courseList.concat(courseList),
                isLoading: false
zhanghaozhe committed
27
            }
zhanghaozhe committed
28 29
        case START_FETCHING_COURSES:
            return {...state, ...action.payload}
zhanghaozhe committed
30 31 32
        case SWITCH_TAB:
            return {...state, switchTab: action.payload}
        case NOMORE_COURSE:
zhanghaozhe committed
33
            return {...state, noMore: true}
zhanghaozhe committed
34 35 36 37
        default:
            return state
    }
}