appActions.js 4.13 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';

const {
	SET_PLATFORM,
	SET_CONTAINER,
	SET_CHANNEL,
	GO_ACTION,

	GO_TO_SECTION,

	GO_TO_POST,
	GO_TO_LIKE_LIST,

	GO_TO_USER,
	GO_TO_USER_THAT_NOT_ME,
	GO_TO_SETTING,

	GO_TO_MESSAGE_CENTER,
    GO_TO_SYS_MESSAGE,
    GO_TO_LIKE_MESSAGE,
} = require('../../constants/actionTypes').default;

export function goToSection(section) {
	Actions.Section();
	return {
		type: GO_TO_SECTION,
        payload: section,
	};
}

export function goToPost(id) {
	Actions.SubjectPost({postId:id});
	return {
		type: GO_TO_POST,
        payload: id,
	};
}

export function goToLikeList(postId, likeCount) {
    Actions.LikeList({title: `共有${likeCount}个赞`});
    return {
		type: GO_TO_LIKE_LIST,
        payload: postId,
	};
}

export function goToUserOrMe(uid) {
    return (dispatch, getState) => {
        let {user} = getState();
        if (uid	!= 0 && uid == user.profile.uid) {
            Actions.User();
			dispatch({
	            type: GO_TO_USER,
	        });
        } else {
            Actions.UserThatNotMe();
			dispatch({
	            type: GO_TO_USER_THAT_NOT_ME,
	            payload: uid,
	        });
        }
	};
}

export function goToUser() {
	return (dispatch, getState) => {
		let operation = () => {
			Actions.User();
			return {
				type: GO_TO_USER,
			};
		};

        let {user} = getState();
        if (user.profile.uid == 0) {
			dispatch(loginThenSyncUserInfo(operation));
        } else {
			dispatch(operation());
        }
	};
}

export function goToUserThatNotMe(uid) {
    return (dispatch, getState) => {
        let {user} = getState();
        if (user.profile.uid == uid) {

        } else {
            Actions.UserThatNotMe();
			dispatch({
	            type: GO_TO_USER_THAT_NOT_ME,
	            payload: uid,
	        });
        }
	};
}

export function goToSetting() {
    Actions.Setting();
    return {
        type: GO_TO_SETTING,
    };
}

export function goToMessageCenter() {
    Actions.MessageCenter();
    return {
        type: GO_TO_MESSAGE_CENTER,
    };
}

export function goToLikeMessage() {
    Actions.LikeMessage();
    return {
        type: GO_TO_LIKE_MESSAGE,
        // payload:
    };
}

export function goToSystemMessage() {
    Actions.SystemMessage();
    return {
        type: GO_TO_SYS_MESSAGE,
        // payload:
    };
}

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);
		if (json === null) {
			return;
		}

		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) {
				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});
		}
	};
}