appActions.js
4.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
/**
* # 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 {loginThenSyncUserInfo} from '../user/userActions';
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,
GO_TO_POSTING,
} = require('../../constants/actionTypes').default;
export function goToSection(section) {
return (dispatch, getState) => {
let {route} = getState();
let tryToClean = route.lastPopScene == 'Section';
Actions.Section();
dispatch({
type: GO_TO_SECTION,
payload: {...section, tryToClean},
});
}
}
export function goToPost(id) {
return (dispatch, getState) => {
let {route} = getState();
let tryToClean = route.lastPopScene == 'SubjectPost';
Actions.SubjectPost({postId:id});
dispatch({
type: GO_TO_POST,
payload: {id, tryToClean},
});
}
}
export function goToLikeList(postId, likeCount) {
return (dispatch, getState) => {
let {route} = getState();
let tryToClean = route.lastPopScene == 'LikeList';
Actions.LikeList({title: `共${likeCount}个赞`});
dispatch({
type: GO_TO_LIKE_LIST,
payload: {postId, tryToClean},
});
}
}
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 {
dispatch(goToUserThatNotMe(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, route} = getState();
if (user.profile.uid == uid) {
} else {
let tryToClean = route.lastPopScene == 'UserThatNotMe';
Actions.UserThatNotMe();
dispatch({
type: GO_TO_USER_THAT_NOT_ME,
payload: {uid, tryToClean},
});
}
};
}
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,
};
}
export function goToSystemMessage() {
Actions.SystemMessage();
return {
type: GO_TO_SYS_MESSAGE,
};
}
export function goToPosting() {
Actions.Posting();
return {
type: GO_TO_POSTING,
};
}
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});
}
};
}