Authored by 于良

Merge branch 'local' into develop

... ... @@ -337,25 +337,10 @@ export default function community(platform) {
return this.navPushStyle(props);
}}
rightTitle='发送'
onRight={()=>{
if (store.getState().posting.dataValid) {
Actions.pop();
store.dispatch(startPosting(store.getState().posting.assets.toJS()));
} else {
// 发布按钮:
// 1.用户编辑内容时,“正文或标题”和“图片”其一必须有内容,否则右上角发布icon置灰,点击文本弹窗提示请输入内容。
// 2.必须有选择的版块,否则右上角发布icon置灰,点击文本弹窗提示请选择版块。两者都没有优先提示请输入内容。
//
let message = '未知';
if (!store.getState().posting.title.length&&!store.getState().posting.content.length) {
message = '请填写标题和内容';
} else if (!store.getState().posting.currentBoardName.length) {
message = '请务必选择模块';
}
Alert.alert('提示',message);
}
onRight={() => {
store.dispatch(startPosting());
}}
rightButtonTextStyle={[styles.barRightButtonText,{color:store.getState().posting.dataValid?'white':'#a0a0a0'}]}
rightButtonTextStyle={[styles.barRightButtonText, {color: store.getState().posting.canSubmit ? 'white' : '#a0a0a0'}]}
onBack={(navigationState) => {
let dismissKeyboard = require('dismissKeyboard');
dismissKeyboard();
... ...
... ... @@ -250,7 +250,7 @@ export default class Home extends React.Component {
}
render() {
let {progressing, banner, notice, section, recommendation, user, endReached, isRefreshing, isLoadingMore, isFetching, isSyncFetching} = this.props;
let {progressing, banner, notice, section, recommendation, user, endReached, isRefreshing, isLoadingMore, isFetching} = this.props;
let dataSource = {
progressing: progressing.toArray(),
banner: banner.toArray(),
... ... @@ -293,7 +293,7 @@ export default class Home extends React.Component {
}}
/>
<LoadingIndicator
isVisible={isSyncFetching}
isVisible={false}
/>
<SuperMan
uid={user.uid}
... ...
... ... @@ -52,7 +52,7 @@ export default class UploadProgress extends React.Component {
let progressBarWidth = 0;
let tips = '';
switch (uploadState) {
case 0:
case 1:
{
// 发布中
tips = '发布中...';
... ... @@ -60,7 +60,7 @@ export default class UploadProgress extends React.Component {
}
break;
case 1:
case 2:
{
// 发布成功
tips = '发布成功';
... ... @@ -69,7 +69,7 @@ export default class UploadProgress extends React.Component {
}
break;
case 2:
case 3:
{
// 发布失败
tips = '发布失败...';
... ... @@ -120,7 +120,7 @@ export default class UploadProgress extends React.Component {
_renderButton(uploadState) {
//根据上传状态不同返回不同按钮
if (uploadState == 2) {
if (uploadState == 3) {
return(
<View style={{flexDirection:'row', width:55,justifyContent:'space-between',marginLeft:15,}}>
... ... @@ -147,7 +147,7 @@ export default class UploadProgress extends React.Component {
</TouchableHighlight>
</View>
);
} else if(uploadState == 1) {
} else if(uploadState == 2) {
return (
<Image
style={styles.complete}
... ...
... ... @@ -97,17 +97,17 @@ export default class AssertsPicker extends Component {
}}
>
<View style={styles.scrollContainer}>
{assets.map((asset, index) => {
return (
<View style={styles.itemContainer} key={index}>
<Image style={styles.item} source={asset}/>
<TouchableOpacity onPress={() => {this.deleteAsset(index);}}>
<Image style={styles.itemDelete} source={require('../../images/posting/delete.png')}/>
</TouchableOpacity>
</View>
);
})}
{this.renderPlus(assets)}
{assets.map((asset, index) => {
return (
<View style={styles.itemContainer} key={index}>
<Image style={styles.item} source={asset}/>
<TouchableOpacity onPress={() => {this.deleteAsset(index);}}>
<Image style={styles.itemDelete} source={require('../../images/posting/delete.png')}/>
</TouchableOpacity>
</View>
);
})}
{this.renderPlus(assets)}
</View>
</ScrollView>
... ...
... ... @@ -64,10 +64,6 @@ export default class Posting extends Component {
this.state.contentInputHeightValue.setValue(contentInputHeight);
Keyboard.addListener('keyboardWillChangeFrame', (event) => {
let keyboardInview = event.endCoordinates.screenY<height;
this.setState({
showKeyboard: keyboardInview,
});
let kbdHeight = height - event.endCoordinates.screenY;
// 键盘高度只获取一次,后面不再获取
... ... @@ -150,11 +146,16 @@ export default class Posting extends Component {
autoFocus={true}
autoCapitalize={'none'}
autoCorrect={false}
onFocus={() => {
this.setState({
showKeyboard: true,
});
}}
onChangeText={(text) => {
this.titleLength = text.length;
this.props.titleEdited(text);
}}
onKeyPress={(event)=>{
onKeyPress={(event) => {
if (this.titleLength >= 30) {
Alert.alert('抱歉','超出30字符最长限制');
}
... ... @@ -171,11 +172,16 @@ export default class Posting extends Component {
maxLength={2000}
multiline={true}
autoCorrect={false}
onFocus={() => {
this.setState({
showKeyboard: true,
});
}}
onChangeText={(text) => {
this.contentLength = text.length;
this.props.contentEdited(text);
}}
onKeyPress={(event)=>{
onKeyPress={(event) => {
if (this.contentLength >= 2000) {
Alert.alert('抱歉','超出2000字符最长限制');
}
... ... @@ -191,7 +197,7 @@ export default class Posting extends Component {
onPressTrigger={this.onPressBlurAll}
onPressSection={this.onPressSectionSelector}
imageInView={this.state.showImagePicker}
keyblardInView={this.state.showKeyboard}
keyboardInView={this.state.showKeyboard}
/>
<AssertsPicker
... ...
... ... @@ -31,9 +31,9 @@ export default class PostingToolBar extends Component {
}
render() {
let {imageCount, selectedSectionName} = this.props;
let keyboardImage = this.props.keyblardInView?require('../../images/jianpan1.png'):require('../../images/keyboard_normal.png');
let picImage = this.props.imageInView?require('../../images/pic1.png'):require('../../images/pic_normal.png')
let {imageCount, selectedSectionName, keyboardInView, imageInView} = this.props;
let keyboardImage = keyboardInView ? require('../../images/jianpan1.png') : require('../../images/keyboard_normal.png');
let picImage = imageInView ? require('../../images/pic1.png') : require('../../images/pic_normal.png')
return (
<View style={styles.container}>
<TouchableOpacity style={styles.imgIcon} onPress={() => {
... ...
... ... @@ -112,17 +112,23 @@ export default keyMirror({
POSTING_BOARD_REQUEST: null,
POSTING_BOARD_SUCCESS: null,
POSTING_BOARD_FAILURE: null,
POSTING_BOARD_SELECTED: null,
POSTING_ASSETS_SELECTED: null,
POSTING_TITLE_EDITED: null,
POSTING_CONTENT_EDITED: null,
POSTING_POST_START: null,
POSTING_POST_SUCCESS: null,
POSTING_POST_FAILURE: null,
POSTING_UPLOAD_UPDATE: null,
POSTING_IMAGE_UPLOAD_SUCCESS: null,
POSTING_POST_FINISHED: null,
POSTING_STATE_RESET: null,
POSTING_STATE_MERGE: null,
POSTING_EVENT_LOGOUT: null,
USER_FORBID_STATE_REQUEST: null,
USER_FORBID_STATE_SUCCESS: null,
USER_FORBID_STATE_FAILURE: null,
... ...
... ... @@ -159,7 +159,7 @@ class HomeContainer extends React.Component {
}
_onPressSectionTag(section) {
this.props.actions.goToSection(section, this.props.navigationState.name);
this.props.actions.goToSection(section);
}
_onPressComment(id) {
... ... @@ -188,10 +188,7 @@ class HomeContainer extends React.Component {
}
_onUploadRetry() {
this.props.actions.startPosting(this.props.posting.assets.toJS());
console.log('upload retry!');
this.props.actions.startPosting();
}
_onUploadDelete() {
... ... @@ -203,10 +200,10 @@ class HomeContainer extends React.Component {
}
render() {
let {inPosting, postFail, finishedCount, postPercent, assets, postingBannerShow, uploadState,} = this.props.posting;
let {postState, post} = this.props.posting;
let assetsData = assets.toJS();
let percent = postPercent;
let assetsData = post.assets.toJS();
let percent = postState.uploadedImagePercent;
let uri = '';
if (assetsData.length) {
uri = assetsData[0].uri;
... ... @@ -215,18 +212,18 @@ class HomeContainer extends React.Component {
}
let progressing = [];
if (postingBannerShow) {
if (postState.showProcess) {
progressing = [{
uploadState,//(0发布中,1发布成功,2发布失败)
progress:percent,//(0~1)
image:uri,
postingBannerShow,
uploadState: postState.status, //(1发布中,2发布成功,3发布失败)
progress: percent,//(0~1)
image: uri,
postingBannerShow: postState.showProcess,
}];
}
progressing = Immutable.fromJS(progressing);
let {banner, notice, section, recommendation, ptr, sync, error, isFetching} = this.props.home;
let {banner, notice, section, recommendation, ptr, error, isFetching} = this.props.home;
let bannerData = Immutable.fromJS([banner.list]);
let noticeData = notice.open === 'Y' ? Immutable.fromJS([notice.list]) : List();
let sectionData = Immutable.fromJS([section]);
... ... @@ -269,7 +266,6 @@ class HomeContainer extends React.Component {
onUploadSuccess={this._onUploadSuccess}
onUploadRetry={this._onUploadRetry}
onUploadDelete={this._onUploadDelete}
isSyncFetching={sync.isFetching}
onSaveingTheWorld={this._onSaveingTheWorld}
ptrError={error}
/>
... ...
... ... @@ -83,17 +83,9 @@ class PostingContainer extends Component{
}
componentWillReceiveProps(nextProps) {
if (this.props.posting.dataValid) {
if (nextProps.posting.dataValid) {
return;
}
Actions.refresh({key: 'Posting', rightButtonTextStyle: {color:'#a0a0a0'}});
} else {
if (!nextProps.posting.dataValid) {
return;
}
Actions.refresh({key: 'Posting', rightButtonTextStyle: {color:'white'}});
if (this.props.posting.canSubmit !== nextProps.posting.canSubmit) {
let color = nextProps.posting.canSubmit ? 'white' : '#a0a0a0';
Actions.refresh({key: 'Posting', rightButtonTextStyle: {color}});
}
}
... ... @@ -110,8 +102,9 @@ class PostingContainer extends Component{
}
contentEdited(content) {
this.props.actions.contentEdited (content);
this.props.actions.contentEdited(content);
}
render() {
let fromSection=false;
if (this.props.section.sid>-1) {
... ... @@ -119,18 +112,22 @@ class PostingContainer extends Component{
fromSection = section.name.length && section.id>0;
}
let {boards, post} = this.props.posting;
post = post.toJS();
let {assets, title, content, sectionName} = post;
return(
<View style={styles.container}>
<Posting
boards={this.props.posting.boards.toJS()}
selectedBoard={this.props.posting.currentBoardName.length?this.props.posting.currentBoardName:'请选择板块'}
boards={boards.list.toJS()}
selectedBoard={sectionName ? sectionName : '请选择板块'}
onBoardPress={this.boardSelectedWithName}
assets={this.props.posting.assets.toJS()}
assets={assets}
assetsSelected={this.assetsSelected}
titleEdited={this.titleEdited}
contentEdited={this.contentEdited}
titleValue={this.props.posting.title}
contentValue={this.props.posting.content}
titleValue={title}
contentValue={content}
fromSection={fromSection}
/>
</View>
... ...
... ... @@ -166,36 +166,28 @@ class SectionContainer extends React.Component {
render() {
let {
inPosting,
postFail,
finishedCount,
postPercent,
assets,
postingBannerShow,
uploadState,
} = this.props.posting;
let assetsData = assets.toJS();
let percent = postPercent;
let {postState, post} = this.props.posting;
let assetsData = post.assets.toJS();
let percent = postState.uploadedImagePercent;
let uri = '';
if (assetsData.length) {
uri = assetsData[0].uri;
}else {
} else {
percent = 1;
}
let progressing = [];
if (postingBannerShow) {
if (postState.showProcess) {
progressing = [{
uploadState,//(0发布中,1发布成功,2发布失败)
progress:percent,//(0~1)
image:uri,
postingBannerShow,
uploadState: postState.status, //(1发布中,2发布成功,3发布失败)
progress: percent,//(0~1)
image: uri,
postingBannerShow: postState.showProcess,
}];
}
progressing = Immutable.fromJS(progressing);
progressing = Immutable.fromJS(progressing);
let section = this.props.section.items.get(this.sid);
let {activeTab, new: newPost, hot: hotPost, header, notice, ptr, isFetching : bnsIsFetching} = section;
... ...
... ... @@ -35,11 +35,6 @@ let InitialState = Record({
list: List(),
endReached: false,
})),
sync: new (Record({
isFetching: false,
error: null,
ssouid: 0,
})),
});
export default InitialState;
... ...
... ... @@ -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 uploadImageStateChanged(payloadData) {
return {
type: POSTING_UPLOAD_UPDATE,
payload:payloadData,
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 postFinished(success) {
return {
type:POSTING_POST_FINISHED,
payload:success,
};
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);
});
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 postSuccess(json) {
return {
type: POSTING_POST_SUCCESS,
payload: json,
};
}
export function postFail() {
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;
}
new PostingService().uploadImageAsset(asset)
.then(response => {
dispatch(updateUploadState(response,asset.name));
}).catch(error => {
dispatch(postFail());
});
}
dispatch(commitImagePost());
} else {
NativeModules.YH_CommunityHelper.uid().then(ssouid => {
let {posting} = getState();
let param = {
postsTitle: posting.title,
uid: ssouid,
forumCode: posting.currentBoardId,
contentData: posting.content,
}
return new PostingService().commitPost(param).then(json => {
store.delete(POSTING_CACHE_KEY);
dispatch(postFinished(true));
}).catch(error => {
dispatch(postFinished(false));
});
});
dispatch(commitTextPost());
}
}); //Cache data before uploading....
})
.catch(error => {
__DEV__ && console.log(error);
});
}
}
export function getBoardList() {
return dispatch => {
dispatch(getBoardRequest());
new PostingService().getBoardList().then(json => {
dispatch(getBoardSuccess(json));
}).catch(error => {
dispatch(getBoardFailure(error));
function shouldCommitPost(state) {
let {posting} = state;
if (posting.canSubmit) {
Actions.pop();
return true;
} else {
// 发布按钮:
// 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 {post} = posting;
let params = {
postsTitle: post.title,
uid: uid,
forumCode: post.sectionId,
contentData: post.content,
}
dispatch(commitPost(params));
});
};
}
}
export function assetsSelected(assets) {
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(postFailure(error));
});
}
}
}
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));
});
}
}
... ...
... ... @@ -15,28 +15,48 @@ import Immutable, {List, Record} from 'immutable';
* The fields we're concerned with
*/
let InitialState = Record({
isFetching: false,
error: null,
currentBoardName: '',
currentBoardId: '',
title: '',
content: '',
boards: List(),
assets: List(),
dataValid: false, //是否可以点击发送
inPosting: false,//正在上传
postFail: false,
finishedCount: 0,
postPercent: 0,
postingBannerShow: false,
uploadState: 0,
// isFetching: false,
// error: null,
// currentBoardName: '',
// currentBoardId: '',
// title: '',
// content: '',
boards: new (Record({
isFetching: false,
error: null,
list: List(),
})),
// assets: List(),
// dataValid: false, //是否可以点击发送
// inPosting: false,//正在上传
// postFail: false,
// finishedCount: 0,
// postPercent: 0,
// postingBannerShow: false,
// uploadState: 0,
userState: new (Record({
isFetching: false,
error: null,
forbidNickname: 'N',
forbidSpeaking: 'N',
})),
canSubmit: false,
post: new (Record({
title: '',
content: '',
sectionId: 0,
sectionName: '',
assets: List(),
})),
postState: new (Record({
isPosting: false,
error: null,
showProcess: true,
status: 0, // 0 - 未发布,1 - 发布中,2 - 发布成功,3 - 发布失败
stage: 0, // 0 - 图片上传,1 - 帖子上传
uploadedImageCount: 0, // 已上传图片数量
uploadedImagePercent: 0, // 已上传图片百分比
})),
});
export default InitialState;
... ...
... ... @@ -16,17 +16,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,
... ... @@ -45,110 +50,106 @@ export default function postingReducer(state = initialState, action) {
switch (action.type) {
case POSTING_STATE_MERGE: {
let nextState = initialState.merge(action.payload);
return state.merge(action.payload);
let {canSubmit, userState, post, postState} = action.payload;
let nextState = state.set('canSubmit', canSubmit)
.setIn(['userState', 'forbidNickname'], userState.forbidNickname)
.setIn(['userState', 'forbidSpeaking'], userState.forbidSpeaking)
.setIn(['post', 'title'], post.title)
.setIn(['post', 'content'], post.content)
.setIn(['post', 'sectionId'], post.sectionId)
.setIn(['post', 'sectionName'], post.sectionName)
.setIn(['post', 'assets'], Immutable.fromJS(post.assets))
.setIn(['postState', 'isPosting'], postState.isPosting)
.setIn(['postState', 'error'], postState.error)
.setIn(['postState', 'showProcess'], postState.showProcess)
.setIn(['postState', 'status'], postState.status)
.setIn(['postState', 'stage'], postState.stage)
.setIn(['postState', 'uploadedImageCount'], postState.uploadedImageCount)
.setIn(['postState', 'uploadedImagePercent'], postState.uploadedImagePercent);
return nextState;
}
break;
case POSTING_EVENT_LOGOUT:
case POSTING_STATE_RESET: {
return initialState;
}
break;
case POSTING_TITLE_EDITED: {
let dataValid=false;
if (action.payload.length) {
dataValid = state.currentBoardName.length>0;
}
let nextState = state.set('title',action.payload).set('dataValid',dataValid);
let {title, canSubmit} = action.payload;
let nextState = state.set('canSubmit', canSubmit)
.setIn(['post', 'title'], title);
return nextState;
}
break;
case POSTING_CONTENT_EDITED: {
let dataValid=false;
if (action.payload.length) {
dataValid = state.currentBoardName.length>0;
}
let nextState = state.set('content',action.payload).set('dataValid',dataValid);
let {content, canSubmit} = action.payload;
let nextState = state.set('canSubmit', canSubmit)
.setIn(['post', 'content'], content);
return nextState;
}
break;
case POSTING_BOARD_REQUEST: {
let nextState = state.set('isFetching', true).set('error', null);
return nextState;
}
break;
case POSTING_BOARD_SUCCESS: {
let boards = action.payload||[];
let nextState = state.set('isFetching',false)
.set('error', null)
.set('boards', Immutable.fromJS(boards));
return nextState;
}
break;
case POSTING_BOARD_FAILURE: {
let nextState = state.set('isFetching', false).set('error', action.payload);
return nextState;
}
break;
case POSTING_BOARD_SELECTED: {
let dataValid=state.title.length>0||state.content.length>0;
let nextState = state.set('currentBoardName',action.payload.boardName).set('currentBoardId',action.payload.boardCode).set('dataValid',dataValid);
let {sectionName, sectionId, canSubmit} = action.payload;
let nextState = state.set('canSubmit', canSubmit)
.setIn(['post', 'sectionName'], sectionName)
.setIn(['post', 'sectionId'], sectionId);
return nextState;
}
break;
case POSTING_ASSETS_SELECTED: {
let data = action.payload||[];
let dataValid=false;
if (data.length) {
dataValid = state.currentBoardName.length>0;
}
let nextState = state.set('assets',Immutable.fromJS(data)).set('dataValid',dataValid);
let assets = action.payload || [];
let nextState = state.setIn(['post', 'assets'], Immutable.fromJS(assets));
return nextState;
}
break;
case POSTING_POST_START: {
let nextState = state.set('inPosting',true).set('postFail',false).set('postingBannerShow',true).set('uploadState',0);
let nextState = state.setIn(['postState', 'isPosting'], true)
.setIn(['postState', 'error'], null)
.setIn(['postState', 'showProcess'], true)
.setIn(['postState', 'status'], 1);
return nextState;
}
break;
case POSTING_UPLOAD_UPDATE: {
case POSTING_POST_SUCCESS: {
let nextState = state.setIn(['postState', 'isPosting'], false)
.setIn(['postState', 'error'], null)
.setIn(['postState', 'status'], 2);
return nextState;
}
let {assets,finishCount,percent} = action.payload;
let nextState = state.set('assets',Immutable.fromJS(assets))
.set('finishedCount',finishCount)
.set('postPercent',percent);
case POSTING_IMAGE_UPLOAD_SUCCESS: {
let {assets, uploadedImageCount, uploadedImagePercent} = action.payload;
let nextState = state.setIn(['post', 'assets'], Immutable.fromJS(assets))
.setIn(['postState', 'uploadedImageCount'], uploadedImageCount)
.setIn(['postState', 'uploadedImagePercent'], uploadedImagePercent);
return nextState;
}
break;
case POSTING_POST_FAILURE: {
let nextState = state.set('inPosting',false).set('postFail',true).set('uploadState',2);
let nextState = state.setIn(['postState', 'isPosting'], false)
.setIn(['postState', 'error'], action.payload)
.setIn(['postState', 'status'], 3);
return nextState;
}
break;
case POSTING_POST_FINISHED: {
let success = action.payload;
let upState = success?1:2
let nextState = state.set('inPosting',!success).set('postFail',!success).set('uploadState',upState);
case POSTING_BOARD_REQUEST: {
let nextState = state.setIn(['boards', 'isFetching'], true)
.setIn(['boards', 'error'], null);
return nextState;
}
case POSTING_BOARD_SUCCESS: {
let nextState = state.setIn(['boards', 'isFetching'], false)
.setIn(['boards', 'error'], null)
.setIn(['boards', 'list'], Immutable.fromJS(action.payload));
return nextState;
}
break;
case POSTING_EVENT_LOGOUT:
return initialState;
break;
case POSTING_BOARD_FAILURE: {
let nextState = state.setIn(['boards', 'isFetching'], false)
.setIn(['boards', 'error'], action.payload);
return nextState;
}
case USER_FORBID_STATE_REQUEST: {
let nextState = state.setIn(['userState', 'isFetching'], true)
... ... @@ -172,7 +173,6 @@ export default function postingReducer(state = initialState, action) {
}
default:
break;
}
... ...
... ... @@ -181,8 +181,8 @@ export default class PostingService {
async uploadImageAsset(asset) {
let formData = new FormData();
formData.append('project','social');//for community ....
formData.append('fileData',{name:asset.name,type: 'image/jpeg','uri':asset.url});
formData.append('project', 'social');
formData.append('fileData', {name: asset.name, type: 'image/jpeg', 'uri': asset.url});
let app_version = DeviceInfo.getBuildNumber();
... ... @@ -192,36 +192,32 @@ export default class PostingService {
let screen_size = width + 'x' + height;
let privateKey = RNNativeConfig.getPrivateKey();
formData.append('app_version',app_version);
formData.append('os_version',os_version);
formData.append('client_type',client_type);
formData.append('screen_size',width + 'x' + height);
formData.append('privateKey',privateKey);
formData.append('app_version', app_version);
formData.append('os_version', os_version);
formData.append('client_type', client_type);
formData.append('screen_size', width + 'x' + height);
formData.append('privateKey', privateKey);
let options = {};
options.body = formData;
options.method = 'post';
options.headers = {'project':'social',HTTP_REFERER:'admin.yohobuy.com'};
console.log('zhixingdao zheli le ..............SSSSSSSSSSSSSSSSSSSSSSSS');
console.log(options);
options.headers = {'project': 'social', HTTP_REFERER: 'admin.yohobuy.com'};
return await fetch('http://upload.static.yohobuy.com', options)
.then((response) => {
return response.json().then(
(json) => {
console.log(json);
if (json.code == 200) {
return json.data.imagesList[0];
}else {
throw(json);
.then((response) => {
return response.json().then(
(json) => {
console.log(json);
if (json.code == 200) {
return json.data.imagesList[0];
} else {
throw(json);
}
}
}
)
}).catch((error) => {
throw(error);
});
)
}).catch((error) => {
throw(error);
});
}
}
... ...