homeActions.js 3.22 KB
/**
 * # guideActions.js
 *
 * App user guide
 *
 */
'use strict';

import {Actions} from 'react-native-router-flux';
import HomeService from '../../services/HomeService';

const {

	HOME_BANNER_REQUEST,
    HOME_BANNER_SUCCESS,
    HOME_BANNER_FAILURE,

    HOME_NOTICE_REQUEST,
    HOME_NOTICE_SUCCESS,
    HOME_NOTICE_FAILURE,

    HOME_SECTION_REQUEST,
    HOME_SECTION_SUCCESS,
    HOME_SECTION_FAILURE,

	HOME_RECOMMENDATION_REQUEST,
    HOME_RECOMMENDATION_SUCCESS,
    HOME_RECOMMENDATION_FAILURE,

} = require('../../constants/actionTypes').default;

export function bannerRequest() {
    return {
        type: HOME_BANNER_REQUEST,
    };
}

export function bannerSuccess(json) {
    return {
        type: HOME_BANNER_SUCCESS,
        payload: json
    };
}

export function bannerFailure(error) {
    return {
        type: HOME_BANNER_FAILURE,
        payload: error
    };
}

export function noticeRequest() {
    return {
        type: HOME_NOTICE_REQUEST,
    };
}

export function noticeSuccess(json) {
    return {
        type: HOME_NOTICE_SUCCESS,
        payload: json
    };
}

export function noticeFailure(error) {
    return {
        type: HOME_NOTICE_FAILURE,
        payload: error
    };
}
export function sectionRequest() {
    return {
        type: HOME_SECTION_REQUEST,
    };
}

export function sectionSuccess(json) {
    return {
        type: HOME_SECTION_SUCCESS,
        payload: json
    };
}

export function sectionFailure(error) {
    return {
        type: HOME_SECTION_FAILURE,
        payload: error
    };
}

export function recommendationRequest() {
    return {
        type: HOME_RECOMMENDATION_REQUEST,
    };
}

export function recommendationSuccess(json) {
    return {
        type: HOME_RECOMMENDATION_SUCCESS,
        payload: json
    };
}

export function recommendationFailure(error) {
    return {
        type: HOME_RECOMMENDATION_FAILURE,
        payload: error
    };
}

export function banner(shopId) {

	return dispatch => {
		dispatch(bannerRequest());
        return new HomeService().banner(shopId)
            .then(json => {
                dispatch(bannerSuccess(json));
            })
            .catch(error => {
                dispatch(bannerFailure(error));
            });
	};
}

export function notice(shopId) {

	return dispatch => {
		dispatch(noticeRequest());
        return new HomeService().notice(shopId)
            .then(json => {
                dispatch(noticeSuccess(json));
            })
            .catch(error => {
                dispatch(noticeFailure(error));
            });
	};
}

export function section(shopId) {

	return dispatch => {
		dispatch(sectionRequest());
        return new HomeService().section(shopId)
            .then(json => {
                dispatch(sectionSuccess(json));
            })
            .catch(error => {
                dispatch(sectionFailure(error));
            });
	};
}

export function recommendation(shopId) {

	return dispatch => {
		dispatch(recommendationRequest());
        return new HomeService().recommendation(shopId)
            .then(json => {
				console.log(json);
                dispatch(recommendationSuccess(json));
            })
            .catch(error => {
                dispatch(recommendationFailure(error));
            });
	};
}