userActions.js 3.04 KB
'use strict'

import {Actions} from 'react-native-router-flux';

import UserService from '../../services/UserService';

const {

    USER_POSTS_REQUEST,
    USER_POSTS_SUCCESS,
    USER_POSTS_FAILURE,

    USER_LIKE_REQUEST,
    USER_LIKE_SUCCESS,
    USER_LIKE_FAILURE,

    USER_REPLY_REQUEST,
    USER_REPLY_SUCCESS,
    USER_REPLY_FAILURE,

    USER_GO_TO_SETTING_STATS,

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

export function postRequest() {
    return {
        type: USER_POSTS_REQUEST
    };
}

export function postSuccess(json) {
    return {
        type: USER_POSTS_SUCCESS,
        payload: json
    };
}

export function postFailure(error) {
    return {
        type: USER_POSTS_FAILURE,
        payload: error
    };
}

export function likeRequest() {
    return {
        type: USER_LIKE_REQUEST
    };
}

export function likeSuccess(json) {
    return {
        type: USER_LIKE_SUCCESS,
        payload: json
    };
}

export function likeFailure(error) {
    return {
        type: USER_LIKE_FAILURE,
        payload: error
    };
}

export function replyRequest() {
    return {
        type: USER_REPLY_REQUEST
    };
}

export function replySuccess(json) {
    return {
        type: USER_REPLY_SUCCESS,
        payload: json
    };
}

export function replyFailure(error) {
    return {
        type: USER_REPLY_FAILURE,
        payload: error
    };
}

export function userInfo() {
    // return dispatch => {
    //     dispatch(postRequest());
    //     return new UserService().posts()
    //         .then(json => {
    //             dispatch(postSuccess(json))
    //         })
    //         .catch(error => {
    //             dispatch(postFailure(error));
    //         });
    // };
}

// 获取【我的帖子】数据
export function posts() {
    return dispatch => {
    //     dispatch(postRequest());
    //     return new UserService().posts()
    //         .then(json => {
                dispatch(postSuccess(postsTestData));
    //         })
    //         .catch(error => {
    //             dispatch(postFailure(error));
    //         });
    };
}

// 获取【我赞过的】数据
export function like() {
    return dispatch => {
        dispatch(likeRequest());
        return new UserService().like()
            .then(json => {
                dispatch(likeSuccess(json))
            })
            .catch(error => {
                dispatch(likeFailure(error));
            });
    };
}

// 获取【我的回复】数据
export function reply() {
    return dispatch => {
        dispatch(replyRequest());
        return new UserService().reply()
            .then(json => {
                dispatch(replySuccess(json))
            })
            .catch(error => {
                dispatch(replyFailure(error));
            });
    };
}

// 页面跳转
export function goToStatsPage(type) {
    switch (type) {
        case USER_GO_TO_SETTING_STATS:
        {
            Actions.SettingStats();
            return {
                type: USER_GO_TO_SETTING_STATS,
            }
        }
            break;
        default:

    }
}