yohoCoinReducer.js 3.48 KB
'use strict';

import InitialState from './yohoCoinInitialState';
import Immutable, {Map} from 'immutable';

const {
	GET_YOHO_COIN_NUM_REQUEST,
	GET_YOHO_COIN_NUM_SUCCESS,
	GET_YOHO_COIN_NUM_FAILURE,

	GET_BANNER_REQUEST,
	GET_BANNER_SUCCESS,
	GET_BANNER_FAILURE,

	GET_WEIXIN_REQUEST,
	GET_WEIXIN_SUCCESS,
	GET_WEIXIN_FAILURE,

	BOY_GIRL_FAVORITE_REQUEST,
	BOY_GIRL_FAVORITE_SUCCESS,
	BOY_GIRL_FAVORITE_FAILURE,

	KIDS_FAVORITE_REQUEST,
	KIDS_FAVORITE_SUCCESS,
	KIDS_FAVORITE_FAILURE,

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

const initialState = new InitialState;

export default function detailReducer(state=initialState, action) {
    switch(action.type) {
    	case GET_YOHO_COIN_NUM_REQUEST: {
			return state.setIn(['yohoCoin', 'isFetching'], true);
    	}
		case GET_YOHO_COIN_NUM_SUCCESS: {
			return state.setIn(['yohoCoin', 'yohocoin_num'], action.payload.yohocoin_num)
			.setIn(['yohoCoin', 'notice'], action.payload.notice)
			.setIn(['yohoCoin', 'isFetching'], false);
		}
		case GET_YOHO_COIN_NUM_FAILURE: {
			return state.setIn(['yohoCoin', 'isFetching'], false)
			.setIn(['yohoCoin', 'error'], action.payload);
		}
		case GET_BANNER_REQUEST: {
			return state.setIn(['banner', 'isFetching'], true);
		}
		case GET_BANNER_SUCCESS: {
			return state.setIn(['banner', 'list'], Immutable.fromJS(action.payload))
			.setIn(['banner', 'isFetching'], false);
		}
		case GET_BANNER_FAILURE: {
			return state.setIn(['banner', 'isFetching'], false)
			.setIn(['banner', 'error'], action.payload);
		}
		case GET_WEIXIN_REQUEST: {
			return state.setIn(['weixin', 'isFetching'], true)
			.setIn(['weixin', 'error'], null);
		}
		case GET_WEIXIN_SUCCESS: {
			return state.setIn(['weixin', 'isFetching'], false)
			.setIn(['weixin', 'error'], null)
			.setIn(['weixin', 'data'], Immutable.fromJS(action.payload));
		}
		case GET_WEIXIN_FAILURE: {
			return state.setIn(['weixin', 'isFetching'], false)
			.setIn(['weixin', 'error'], action.payload);
		}
		case BOY_GIRL_FAVORITE_REQUEST: {
			return state.setIn(['favorite', 'isFetching'], true)
			.setIn(['favorite', 'error'], null);
		}
		case BOY_GIRL_FAVORITE_SUCCESS: {
			return state.setIn(['favorite', 'isFetching'], false)
			.setIn(['favorite', 'error'], null)
			.setIn(['favorite', 'currentPage'], action.payload.currentPage)
			.setIn(['favorite', 'endReached'], action.payload.endReached)
			.setIn(['favorite', 'list'], Immutable.fromJS(action.payload.list))
			.setIn(['favorite', 'pageCount'], action.payload.pageCount)
			.setIn(['favorite', 'rec_id'], action.payload.rec_id)
			.setIn(['favorite', 'total'], action.payload.total)
		}
		case BOY_GIRL_FAVORITE_FAILURE: {
			return state.setIn(['favorite', 'isFetching'], false)
			.setIn(['favorite', 'error'], action.payload);
		}
		case KIDS_FAVORITE_REQUEST: {
			return state.setIn(['favorite', 'isFetching'], true)
			.setIn(['favorite', 'error'], null);
		}
		case KIDS_FAVORITE_SUCCESS: {
			return state.setIn(['favorite', 'isFetching'], false)
			.setIn(['favorite', 'error'], null)
			.setIn(['favorite', 'currentPage'], action.payload.currentPage)
			.setIn(['favorite', 'endReached'], action.payload.endReached)
			.setIn(['favorite', 'list'], Immutable.fromJS(action.payload.list))
			.setIn(['favorite', 'pageCount'], action.payload.pageCount)
			.setIn(['favorite', 'rec_id'], '')
			.setIn(['favorite', 'total'], action.payload.total)
		}
		case KIDS_FAVORITE_FAILURE: {
			return state.setIn(['favorite', 'isFetching'], false)
			.setIn(['favorite', 'error'], action.payload);
		}
    }
    return state;
}