appActions.js 1.95 KB
/**
 * # guideActions.js
 *
 * App user guide
 *
 */
'use strict';

import ReactNative from 'react-native';
import {Actions} from 'react-native-router-flux';
import Immutable, {Map} from 'immutable';
import AppService from '../../services/AppService';
import RouterService from '../../services/RouterService';
import {goToSection, goToPost} from '../home/homeActions';

const {
	SET_PLATFORM,
	SET_CONTAINER,
	SET_CHANNEL,
	GO_ACTION,
} = require('../../constants/actionTypes').default;

export function setPlatform(platform) {
    return {
        type: SET_PLATFORM,
        payload: platform
    };
}

export function setContianer(container) {
    return {
        type: SET_CONTAINER,
        payload: container
    };
}

export function setChannel(channel) {
    return {
        type: SET_CHANNEL,
        payload: channel
    };
}

export function goAction(inputUrl) {
	return (dispatch, getState) => {
		let json = new RouterService().parseUrl(inputUrl);
		let {action, params} = json;
		let {param, share, shareparam, title, url} = params;

		if (action == 'go.comm.forum') {
			let id = params && params.forumid ? params.forumid : 0;
			let name = '';
			if (id != 0) {
				dispatch(goToSection({id, name}));
			}

		} else if (action == 'go.comm.postdetail') {
			let id = params && params.postId ? params.postId : 0;
			if (id != 0) {
				dispatch(goToPost(id));
			}

		} else if (action == 'go.comm.h5') {
			let title = params.title ? params.title : '';
			let url = params.url ? params.url : '';
			if (!url || url.length == 0) {
				return;
			}
			ReactNative.NativeModules.YH_CommunityHelper.displayH5({url, title});
		} else if (action == 'go.comm.productDetail') {
			let productSkn = params.product_skn ? params.product_skn : '';
			productSkn = productSkn + '';
			let tag = params.tag ? params.tag : '';
			if (!productSkn || productSkn.length == 0) {
				return;
			}
			ReactNative.NativeModules.YH_CommunityHelper.displayProductDetail({productSkn, tag});
		}
	};
}