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

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

const {

	HOME_BANNER_AND_SECTION_REQUEST,
    HOME_BANNER_AND_SECTION_SUCCESS,
    HOME_BANNER_AND_SECTION_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 bannerAndSectionRequest() {
    return {
        type: HOME_BANNER__AND_SECTIONREQUEST,
    };
}

export function bannerAndSectionSuccess(json) {
    return {
        type: HOME_BANNER_AND_SECTION_SUCCESS,
        payload: json
    };
}

export function bannerAndSectionFailure(error) {
    return {
        type: HOME_BANNER_AND_SECTION_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 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 bannerAndSection() {
	return dispatch => {
		dispatch(bannerAndSectionRequest());
        return new HomeService().bannerAndSection(appType)
            .then(json => {
                dispatch(bannerAndSectionSuccess(json));
            })
            .catch(error => {
                dispatch(bannerAndSectionFailure(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));
            });
	};
}