import {api, getParam, http} from "@/utils";

export const RECEIVE_COURSES_DETAIL = 'RECEIVE_COURSES_DETAIL'
export const receiveCourseDetail = payload => ({
    type: RECEIVE_COURSES_DETAIL,
    payload
})

export const fetchCoursesListIfNeeded = () => (dispatch, getState) => {
    dispatch(getCourses({
        courseInfo: getState().detailInfo
    }))
}
export const getCourses = payload => dispatch => {
    return http.get(`${API.home}/m/course/detail/${getParam('id')}`,).then((res) => {
        if (res.data.code === 200) {
            dispatch(receiveCourseDetail({
                ...res.data.data
            }))
        }
    })
}
