...
|
...
|
@@ -23,17 +23,22 @@ const { |
|
|
POSTING_BOARD_REQUEST,
|
|
|
POSTING_BOARD_SUCCESS,
|
|
|
POSTING_BOARD_FAILURE,
|
|
|
|
|
|
POSTING_BOARD_SELECTED,
|
|
|
POSTING_ASSETS_SELECTED,
|
|
|
POSTING_TITLE_EDITED,
|
|
|
POSTING_CONTENT_EDITED,
|
|
|
|
|
|
POSTING_POST_START,
|
|
|
POSTING_POST_SUCCESS,
|
|
|
POSTING_POST_FAILURE,
|
|
|
POSTING_UPLOAD_UPDATE,
|
|
|
|
|
|
POSTING_IMAGE_UPLOAD_SUCCESS,
|
|
|
POSTING_POST_FINISHED,
|
|
|
POSTING_STATE_RESET,
|
|
|
POSTING_STATE_MERGE,
|
|
|
POSTING_EVENT_LOGOUT,
|
|
|
|
|
|
USER_FORBID_STATE_REQUEST,
|
|
|
USER_FORBID_STATE_SUCCESS,
|
|
|
USER_FORBID_STATE_FAILURE,
|
...
|
...
|
@@ -41,6 +46,34 @@ const { |
|
|
|
|
|
let POSTING_CACHE_KEY = 'POSTING_CACHE_KEY';
|
|
|
|
|
|
|
|
|
export function commitMerge(cachedObj) {
|
|
|
return {
|
|
|
type: POSTING_STATE_MERGE,
|
|
|
payload: cachedObj,
|
|
|
};
|
|
|
}
|
|
|
|
|
|
export function mergeCachedPosting() {
|
|
|
return dispatch => {
|
|
|
store.get(POSTING_CACHE_KEY)
|
|
|
.then((cachedObj)=>{
|
|
|
if (cachedObj) {
|
|
|
// let canSubmit = canSubmitPost(getState(), title, null, null);
|
|
|
dispatch(commitMerge(cachedObj));
|
|
|
}
|
|
|
})
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
export function resetState() {
|
|
|
YH_CommunityAssetsPicker.resetState();
|
|
|
return {
|
|
|
type: POSTING_STATE_RESET,
|
|
|
};
|
|
|
}
|
|
|
|
|
|
export function postingEventLogOut() {
|
|
|
store.delete(POSTING_CACHE_KEY);
|
|
|
return {
|
...
|
...
|
@@ -51,7 +84,7 @@ export function postingEventLogOut() { |
|
|
export function startEditPost(postingState) {
|
|
|
return (dispatch, getState) => {
|
|
|
let {posting, user} = getState();
|
|
|
if (posting.inPosting) {
|
|
|
if (posting.postState.isPosting) {
|
|
|
Alert.alert('抱歉','您有正在发送的帖子,请耐心等待~');
|
|
|
return;
|
|
|
}
|
...
|
...
|
@@ -106,52 +139,67 @@ export function drillToEditPostPage() { |
|
|
dispatch(goToPosting());
|
|
|
}
|
|
|
}).catch(error => {
|
|
|
dispatch(userForbidStateRequest(error));
|
|
|
dispatch(userForbidStateFailure(error));
|
|
|
dispatch(goToPosting());
|
|
|
__DEV__ && console.log(error);
|
|
|
})
|
|
|
}
|
|
|
}
|
|
|
|
|
|
export function commitMerge(cachedObj) {
|
|
|
return {
|
|
|
type: POSTING_STATE_MERGE,
|
|
|
payload: Immutable.fromJS(cachedObj),
|
|
|
};
|
|
|
export function titleEdited(title) {
|
|
|
return (dispatch, getState) => {
|
|
|
let canSubmit = canSubmitPost(getState(), title, null, null);
|
|
|
dispatch({
|
|
|
type: POSTING_TITLE_EDITED,
|
|
|
payload: {title, canSubmit},
|
|
|
});
|
|
|
}
|
|
|
}
|
|
|
|
|
|
export function mergeCachedPosting() {
|
|
|
return dispatch => {
|
|
|
store.get(POSTING_CACHE_KEY)
|
|
|
.then((cachedObj)=>{
|
|
|
if (cachedObj) {
|
|
|
dispatch(commitMerge(cachedObj));
|
|
|
dispatch(startPosting(cachedObj.assets));
|
|
|
}
|
|
|
})
|
|
|
export function contentEdited(content) {
|
|
|
return (dispatch, getState) => {
|
|
|
let canSubmit = canSubmitPost(getState(), null, content, null);
|
|
|
dispatch({
|
|
|
type: POSTING_CONTENT_EDITED,
|
|
|
payload: {content, canSubmit},
|
|
|
});
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
export function titleEdited(title) {
|
|
|
return {
|
|
|
type:POSTING_TITLE_EDITED,
|
|
|
payload: title,
|
|
|
};
|
|
|
export function boardSelected(sectionName, sectionId) {
|
|
|
return (dispatch, getState) => {
|
|
|
let canSubmit = canSubmitPost(getState(), null, null, sectionName);
|
|
|
dispatch({
|
|
|
type: POSTING_BOARD_SELECTED,
|
|
|
payload: {sectionName, sectionId, canSubmit},
|
|
|
});
|
|
|
}
|
|
|
}
|
|
|
|
|
|
export function contentEdited(content) {
|
|
|
export function assetsSelected(assets) {
|
|
|
return {
|
|
|
type: POSTING_CONTENT_EDITED,
|
|
|
payload: content,
|
|
|
type: POSTING_ASSETS_SELECTED,
|
|
|
payload: assets,
|
|
|
};
|
|
|
}
|
|
|
|
|
|
export function boardSelected(boardName,boardCode) {
|
|
|
return {
|
|
|
type: POSTING_BOARD_SELECTED,
|
|
|
payload: {boardName, boardCode},
|
|
|
};
|
|
|
function canSubmitPost(state, newTitle = null, newContent = null, newSectionName = null) {
|
|
|
let {posting} = state;
|
|
|
let {post} = posting;
|
|
|
let {title, content, sectionName} = post;
|
|
|
|
|
|
let canSubmitPost = false;
|
|
|
|
|
|
let titleValue = newTitle !== null ? newTitle : title;
|
|
|
let contentValue = newContent !== null ? newContent : content;
|
|
|
let sectionNameValue = newSectionName !== null ? newSectionName : sectionName;
|
|
|
|
|
|
let hasTitleOrContent = titleValue.length > 0 || contentValue.length > 0;
|
|
|
let hasSection = sectionNameValue.length > 0;
|
|
|
if (hasTitleOrContent && hasSection) {
|
|
|
canSubmitPost = true;
|
|
|
}
|
|
|
|
|
|
return canSubmitPost;
|
|
|
}
|
|
|
|
|
|
export function getBoardRequest() {
|
...
|
...
|
@@ -174,27 +222,49 @@ export function getBoardFailure(error) { |
|
|
};
|
|
|
}
|
|
|
|
|
|
export function postStart() {
|
|
|
return {
|
|
|
type: POSTING_POST_START,
|
|
|
export function getBoardList() {
|
|
|
return dispatch => {
|
|
|
dispatch(getBoardRequest());
|
|
|
new PostingService().getBoardList().then(json => {
|
|
|
let payload = parseBoards(json);
|
|
|
dispatch(getBoardSuccess(payload));
|
|
|
}).catch(error => {
|
|
|
dispatch(getBoardFailure(error));
|
|
|
});
|
|
|
};
|
|
|
}
|
|
|
|
|
|
export function uploadImageStateChanged(payloadData) {
|
|
|
return {
|
|
|
type: POSTING_UPLOAD_UPDATE,
|
|
|
payload:payloadData,
|
|
|
function parseBoards(json) {
|
|
|
let list = [];
|
|
|
json && json.map((item, i) => {
|
|
|
let {authorInfo, blocks} = item;
|
|
|
|
|
|
let forumCode = item.forumCode ? item.forumCode : 0;
|
|
|
let forumDesc = item.forumDesc ? item.forumDesc : '';
|
|
|
let forumName = item.forumName ? item.forumName : '';
|
|
|
let forumPic = item.forumPic ? item.forumPic : '';
|
|
|
let orderBy = item.orderBy ? item.orderBy : 0;
|
|
|
let position = item.position ? item.position : 0;
|
|
|
let magazineAdvertCode = item.magazineAdvertCode ? item.magazineAdvertCode : '';
|
|
|
let yohoAdvertCode = item.yohoAdvertCode ? item.yohoAdvertCode : '';
|
|
|
let section = {
|
|
|
forumCode,
|
|
|
forumDesc,
|
|
|
forumName,
|
|
|
forumPic,
|
|
|
orderBy,
|
|
|
position,
|
|
|
magazineAdvertCode,
|
|
|
yohoAdvertCode,
|
|
|
};
|
|
|
}
|
|
|
list.push(section);
|
|
|
});
|
|
|
|
|
|
export function postFinished(success) {
|
|
|
return {
|
|
|
type:POSTING_POST_FINISHED,
|
|
|
payload:success,
|
|
|
};
|
|
|
return list;
|
|
|
}
|
|
|
|
|
|
export function updateUploadState(url,fileName) {
|
|
|
/*
|
|
|
export function updateUploadState(url, fileName) {
|
|
|
|
|
|
return (dispatch, getState) => {
|
|
|
|
...
|
...
|
@@ -243,79 +313,177 @@ export function updateUploadState(url,fileName) { |
|
|
});
|
|
|
}
|
|
|
}
|
|
|
*/
|
|
|
|
|
|
export function resetState() {
|
|
|
YH_CommunityAssetsPicker.resetState();
|
|
|
export function postStart() {
|
|
|
return {
|
|
|
type: POSTING_STATE_RESET,
|
|
|
type: POSTING_POST_START,
|
|
|
};
|
|
|
}
|
|
|
|
|
|
export function postFail() {
|
|
|
export function postSuccess(json) {
|
|
|
return {
|
|
|
type: POSTING_POST_SUCCESS,
|
|
|
payload: json,
|
|
|
};
|
|
|
}
|
|
|
|
|
|
export function postFailure(error) {
|
|
|
return {
|
|
|
type: POSTING_POST_FAILURE,
|
|
|
payload: error
|
|
|
};
|
|
|
}
|
|
|
|
|
|
export function startPosting(assets) {
|
|
|
export function startPosting() {
|
|
|
|
|
|
return (dispatch, getState) => {
|
|
|
let state = getState();
|
|
|
if (!shouldCommitPost(state)) {
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
let {posting} = state;
|
|
|
let {post} = posting;
|
|
|
let {assets} = post;
|
|
|
assets = assets.toJS();
|
|
|
|
|
|
dispatch(postStart());
|
|
|
|
|
|
let storedState = getState().posting.toJS();
|
|
|
let storedState = posting.toJS();
|
|
|
storedState.boards = [];
|
|
|
storedState.postingBannerShow = true;
|
|
|
store.save(POSTING_CACHE_KEY,storedState).then(()=>{
|
|
|
store.get(POSTING_CACHE_KEY).then((data)=>{
|
|
|
})
|
|
|
storedState.postState.isPosting = true;
|
|
|
storedState.postState.status = 3;
|
|
|
storedState.postState.showProcess = true;
|
|
|
store.save(POSTING_CACHE_KEY, storedState)
|
|
|
.then(() => {
|
|
|
if (assets.length) {
|
|
|
for (let i = 0; i < assets.length; i++) {
|
|
|
let asset = assets[i]
|
|
|
if (asset.finished) {
|
|
|
continue;
|
|
|
dispatch(commitImagePost());
|
|
|
} else {
|
|
|
dispatch(commitTextPost());
|
|
|
}
|
|
|
new PostingService().uploadImageAsset(asset)
|
|
|
.then(response => {
|
|
|
dispatch(updateUploadState(response,asset.name));
|
|
|
}).catch(error => {
|
|
|
dispatch(postFail());
|
|
|
})
|
|
|
.catch(error => {
|
|
|
__DEV__ && console.log(error);
|
|
|
});
|
|
|
}
|
|
|
}
|
|
|
|
|
|
function shouldCommitPost(state) {
|
|
|
let {posting} = state;
|
|
|
if (posting.canSubmit) {
|
|
|
Actions.pop();
|
|
|
|
|
|
return true;
|
|
|
} else {
|
|
|
NativeModules.YH_CommunityHelper.uid().then(ssouid => {
|
|
|
// 发布按钮:
|
|
|
// 1.用户编辑内容时,“正文或标题”其一必须有内容,否则右上角发布icon置灰,点击文本弹窗提示请输入内容。
|
|
|
// 2.必须有选择的版块,否则右上角发布icon置灰,点击文本弹窗提示请选择版块。两者都没有优先提示请输入内容。
|
|
|
//
|
|
|
let {post} = posting;
|
|
|
let message = '未知';
|
|
|
if (!post.title && !post.content) {
|
|
|
message = '请填写标题和内容';
|
|
|
} else if (!post.sectionName) {
|
|
|
message = '请选择版块';
|
|
|
}
|
|
|
|
|
|
Alert.alert('提示', message);
|
|
|
|
|
|
return false;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
function commitTextPost() {
|
|
|
return (dispatch, getState) => {
|
|
|
NativeModules.YH_CommunityHelper.uid().then(uid => {
|
|
|
let {posting} = getState();
|
|
|
let param = {
|
|
|
postsTitle: posting.title,
|
|
|
uid: ssouid,
|
|
|
forumCode: posting.currentBoardId,
|
|
|
contentData: posting.content,
|
|
|
let {post} = posting;
|
|
|
let params = {
|
|
|
postsTitle: post.title,
|
|
|
uid: uid,
|
|
|
forumCode: post.sectionId,
|
|
|
contentData: post.content,
|
|
|
}
|
|
|
return new PostingService().commitPost(param).then(json => {
|
|
|
store.delete(POSTING_CACHE_KEY);
|
|
|
dispatch(postFinished(true));
|
|
|
}).catch(error => {
|
|
|
dispatch(postFinished(false));
|
|
|
});
|
|
|
dispatch(commitPost(params));
|
|
|
});
|
|
|
}
|
|
|
}); //Cache data before uploading....
|
|
|
}
|
|
|
}
|
|
|
|
|
|
export function getBoardList() {
|
|
|
return dispatch => {
|
|
|
dispatch(getBoardRequest());
|
|
|
new PostingService().getBoardList().then(json => {
|
|
|
dispatch(getBoardSuccess(json));
|
|
|
function commitImagePost() {
|
|
|
return (dispatch, getState) => {
|
|
|
let {posting} = getState();
|
|
|
let {post} = posting;
|
|
|
let {assets} = post;
|
|
|
assets = assets.toJS();
|
|
|
for (let i = 0; i < assets.length; i++) {
|
|
|
let asset = assets[i]
|
|
|
if (asset.finished) {
|
|
|
continue;
|
|
|
}
|
|
|
new PostingService().uploadImageAsset(asset)
|
|
|
.then(json => {
|
|
|
dispatch(uploadImageSuccess(json, i));
|
|
|
}).catch(error => {
|
|
|
dispatch(getBoardFailure(error));
|
|
|
dispatch(postFailure(error));
|
|
|
});
|
|
|
};
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
export function assetsSelected(assets) {
|
|
|
export function uploadImageStateChanged(payload) {
|
|
|
return {
|
|
|
type: POSTING_ASSETS_SELECTED,
|
|
|
payload: assets,
|
|
|
type: POSTING_IMAGE_UPLOAD_SUCCESS,
|
|
|
payload: payload,
|
|
|
};
|
|
|
}
|
|
|
|
|
|
function uploadImageSuccess(imageUrl, index) {
|
|
|
return (dispatch, getState) => {
|
|
|
let {posting, user} = getState();
|
|
|
let {post, postState} = posting;
|
|
|
let {assets} = post;
|
|
|
assets = assets.toJS();
|
|
|
assets[index].webURL = imageUrl;
|
|
|
assets[index].finished = true;
|
|
|
|
|
|
let uploadedImageCount = postState.uploadedImageCount;
|
|
|
uploadedImageCount++;
|
|
|
let uploadedImagePercent = parseFloat(uploadedImageCount) / assets.length;
|
|
|
let payload = {assets, uploadedImageCount, uploadedImagePercent};
|
|
|
|
|
|
dispatch(uploadImageStateChanged(payload));
|
|
|
|
|
|
// 图片全部上传完成,上传帖子其他信息
|
|
|
if (uploadedImageCount == assets.length) {
|
|
|
let imageStr = '';
|
|
|
let sizeStr = '';
|
|
|
for (let i = 0; i < assets.length; i++) {
|
|
|
imageStr += assets[i].webURL + ',';
|
|
|
sizeStr += assets[i].width + 'x' + assets[i].height +',';
|
|
|
}
|
|
|
let params = {
|
|
|
postsTitle: post.title,
|
|
|
uid: user.profile.uid,
|
|
|
forumCode: post.sectionId,
|
|
|
contentData: post.content,
|
|
|
images: imageStr,
|
|
|
sizes: sizeStr,
|
|
|
}
|
|
|
dispatch(commitPost(params));
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
function commitPost(params) {
|
|
|
return dispatch => {
|
|
|
return new PostingService().commitPost(params)
|
|
|
.then((json) => {
|
|
|
store.delete(POSTING_CACHE_KEY);
|
|
|
dispatch(postSuccess(json));
|
|
|
})
|
|
|
.catch(error => {
|
|
|
dispatch(postFailure(error));
|
|
|
});
|
|
|
}
|
|
|
} |
...
|
...
|
|