Merge branch 'local' into develop
Showing
15 changed files
with
472 additions
and
311 deletions
@@ -337,25 +337,10 @@ export default function community(platform) { | @@ -337,25 +337,10 @@ export default function community(platform) { | ||
337 | return this.navPushStyle(props); | 337 | return this.navPushStyle(props); |
338 | }} | 338 | }} |
339 | rightTitle='发送' | 339 | rightTitle='发送' |
340 | - onRight={()=>{ | ||
341 | - if (store.getState().posting.dataValid) { | ||
342 | - Actions.pop(); | ||
343 | - store.dispatch(startPosting(store.getState().posting.assets.toJS())); | ||
344 | - } else { | ||
345 | - // 发布按钮: | ||
346 | - // 1.用户编辑内容时,“正文或标题”和“图片”其一必须有内容,否则右上角发布icon置灰,点击文本弹窗提示请输入内容。 | ||
347 | - // 2.必须有选择的版块,否则右上角发布icon置灰,点击文本弹窗提示请选择版块。两者都没有优先提示请输入内容。 | ||
348 | - // | ||
349 | - let message = '未知'; | ||
350 | - if (!store.getState().posting.title.length&&!store.getState().posting.content.length) { | ||
351 | - message = '请填写标题和内容'; | ||
352 | - } else if (!store.getState().posting.currentBoardName.length) { | ||
353 | - message = '请务必选择模块'; | ||
354 | - } | ||
355 | - Alert.alert('提示',message); | ||
356 | - } | 340 | + onRight={() => { |
341 | + store.dispatch(startPosting()); | ||
357 | }} | 342 | }} |
358 | - rightButtonTextStyle={[styles.barRightButtonText,{color:store.getState().posting.dataValid?'white':'#a0a0a0'}]} | 343 | + rightButtonTextStyle={[styles.barRightButtonText, {color: store.getState().posting.canSubmit ? 'white' : '#a0a0a0'}]} |
359 | onBack={(navigationState) => { | 344 | onBack={(navigationState) => { |
360 | let dismissKeyboard = require('dismissKeyboard'); | 345 | let dismissKeyboard = require('dismissKeyboard'); |
361 | dismissKeyboard(); | 346 | dismissKeyboard(); |
@@ -250,7 +250,7 @@ export default class Home extends React.Component { | @@ -250,7 +250,7 @@ export default class Home extends React.Component { | ||
250 | } | 250 | } |
251 | 251 | ||
252 | render() { | 252 | render() { |
253 | - let {progressing, banner, notice, section, recommendation, user, endReached, isRefreshing, isLoadingMore, isFetching, isSyncFetching} = this.props; | 253 | + let {progressing, banner, notice, section, recommendation, user, endReached, isRefreshing, isLoadingMore, isFetching} = this.props; |
254 | let dataSource = { | 254 | let dataSource = { |
255 | progressing: progressing.toArray(), | 255 | progressing: progressing.toArray(), |
256 | banner: banner.toArray(), | 256 | banner: banner.toArray(), |
@@ -293,7 +293,7 @@ export default class Home extends React.Component { | @@ -293,7 +293,7 @@ export default class Home extends React.Component { | ||
293 | }} | 293 | }} |
294 | /> | 294 | /> |
295 | <LoadingIndicator | 295 | <LoadingIndicator |
296 | - isVisible={isSyncFetching} | 296 | + isVisible={false} |
297 | /> | 297 | /> |
298 | <SuperMan | 298 | <SuperMan |
299 | uid={user.uid} | 299 | uid={user.uid} |
@@ -52,7 +52,7 @@ export default class UploadProgress extends React.Component { | @@ -52,7 +52,7 @@ export default class UploadProgress extends React.Component { | ||
52 | let progressBarWidth = 0; | 52 | let progressBarWidth = 0; |
53 | let tips = ''; | 53 | let tips = ''; |
54 | switch (uploadState) { | 54 | switch (uploadState) { |
55 | - case 0: | 55 | + case 1: |
56 | { | 56 | { |
57 | // 发布中 | 57 | // 发布中 |
58 | tips = '发布中...'; | 58 | tips = '发布中...'; |
@@ -60,7 +60,7 @@ export default class UploadProgress extends React.Component { | @@ -60,7 +60,7 @@ export default class UploadProgress extends React.Component { | ||
60 | } | 60 | } |
61 | break; | 61 | break; |
62 | 62 | ||
63 | - case 1: | 63 | + case 2: |
64 | { | 64 | { |
65 | // 发布成功 | 65 | // 发布成功 |
66 | tips = '发布成功'; | 66 | tips = '发布成功'; |
@@ -69,7 +69,7 @@ export default class UploadProgress extends React.Component { | @@ -69,7 +69,7 @@ export default class UploadProgress extends React.Component { | ||
69 | } | 69 | } |
70 | break; | 70 | break; |
71 | 71 | ||
72 | - case 2: | 72 | + case 3: |
73 | { | 73 | { |
74 | // 发布失败 | 74 | // 发布失败 |
75 | tips = '发布失败...'; | 75 | tips = '发布失败...'; |
@@ -120,7 +120,7 @@ export default class UploadProgress extends React.Component { | @@ -120,7 +120,7 @@ export default class UploadProgress extends React.Component { | ||
120 | 120 | ||
121 | _renderButton(uploadState) { | 121 | _renderButton(uploadState) { |
122 | //根据上传状态不同返回不同按钮 | 122 | //根据上传状态不同返回不同按钮 |
123 | - if (uploadState == 2) { | 123 | + if (uploadState == 3) { |
124 | return( | 124 | return( |
125 | <View style={{flexDirection:'row', width:55,justifyContent:'space-between',marginLeft:15,}}> | 125 | <View style={{flexDirection:'row', width:55,justifyContent:'space-between',marginLeft:15,}}> |
126 | 126 | ||
@@ -147,7 +147,7 @@ export default class UploadProgress extends React.Component { | @@ -147,7 +147,7 @@ export default class UploadProgress extends React.Component { | ||
147 | </TouchableHighlight> | 147 | </TouchableHighlight> |
148 | </View> | 148 | </View> |
149 | ); | 149 | ); |
150 | - } else if(uploadState == 1) { | 150 | + } else if(uploadState == 2) { |
151 | return ( | 151 | return ( |
152 | <Image | 152 | <Image |
153 | style={styles.complete} | 153 | style={styles.complete} |
@@ -97,17 +97,17 @@ export default class AssertsPicker extends Component { | @@ -97,17 +97,17 @@ export default class AssertsPicker extends Component { | ||
97 | }} | 97 | }} |
98 | > | 98 | > |
99 | <View style={styles.scrollContainer}> | 99 | <View style={styles.scrollContainer}> |
100 | - {assets.map((asset, index) => { | ||
101 | - return ( | ||
102 | - <View style={styles.itemContainer} key={index}> | ||
103 | - <Image style={styles.item} source={asset}/> | ||
104 | - <TouchableOpacity onPress={() => {this.deleteAsset(index);}}> | ||
105 | - <Image style={styles.itemDelete} source={require('../../images/posting/delete.png')}/> | ||
106 | - </TouchableOpacity> | ||
107 | - </View> | ||
108 | - ); | ||
109 | - })} | ||
110 | - {this.renderPlus(assets)} | 100 | + {assets.map((asset, index) => { |
101 | + return ( | ||
102 | + <View style={styles.itemContainer} key={index}> | ||
103 | + <Image style={styles.item} source={asset}/> | ||
104 | + <TouchableOpacity onPress={() => {this.deleteAsset(index);}}> | ||
105 | + <Image style={styles.itemDelete} source={require('../../images/posting/delete.png')}/> | ||
106 | + </TouchableOpacity> | ||
107 | + </View> | ||
108 | + ); | ||
109 | + })} | ||
110 | + {this.renderPlus(assets)} | ||
111 | </View> | 111 | </View> |
112 | 112 | ||
113 | </ScrollView> | 113 | </ScrollView> |
@@ -64,10 +64,6 @@ export default class Posting extends Component { | @@ -64,10 +64,6 @@ export default class Posting extends Component { | ||
64 | this.state.contentInputHeightValue.setValue(contentInputHeight); | 64 | this.state.contentInputHeightValue.setValue(contentInputHeight); |
65 | 65 | ||
66 | Keyboard.addListener('keyboardWillChangeFrame', (event) => { | 66 | Keyboard.addListener('keyboardWillChangeFrame', (event) => { |
67 | - let keyboardInview = event.endCoordinates.screenY<height; | ||
68 | - this.setState({ | ||
69 | - showKeyboard: keyboardInview, | ||
70 | - }); | ||
71 | let kbdHeight = height - event.endCoordinates.screenY; | 67 | let kbdHeight = height - event.endCoordinates.screenY; |
72 | 68 | ||
73 | // 键盘高度只获取一次,后面不再获取 | 69 | // 键盘高度只获取一次,后面不再获取 |
@@ -150,11 +146,16 @@ export default class Posting extends Component { | @@ -150,11 +146,16 @@ export default class Posting extends Component { | ||
150 | autoFocus={true} | 146 | autoFocus={true} |
151 | autoCapitalize={'none'} | 147 | autoCapitalize={'none'} |
152 | autoCorrect={false} | 148 | autoCorrect={false} |
149 | + onFocus={() => { | ||
150 | + this.setState({ | ||
151 | + showKeyboard: true, | ||
152 | + }); | ||
153 | + }} | ||
153 | onChangeText={(text) => { | 154 | onChangeText={(text) => { |
154 | this.titleLength = text.length; | 155 | this.titleLength = text.length; |
155 | this.props.titleEdited(text); | 156 | this.props.titleEdited(text); |
156 | }} | 157 | }} |
157 | - onKeyPress={(event)=>{ | 158 | + onKeyPress={(event) => { |
158 | if (this.titleLength >= 30) { | 159 | if (this.titleLength >= 30) { |
159 | Alert.alert('抱歉','超出30字符最长限制'); | 160 | Alert.alert('抱歉','超出30字符最长限制'); |
160 | } | 161 | } |
@@ -171,11 +172,16 @@ export default class Posting extends Component { | @@ -171,11 +172,16 @@ export default class Posting extends Component { | ||
171 | maxLength={2000} | 172 | maxLength={2000} |
172 | multiline={true} | 173 | multiline={true} |
173 | autoCorrect={false} | 174 | autoCorrect={false} |
175 | + onFocus={() => { | ||
176 | + this.setState({ | ||
177 | + showKeyboard: true, | ||
178 | + }); | ||
179 | + }} | ||
174 | onChangeText={(text) => { | 180 | onChangeText={(text) => { |
175 | this.contentLength = text.length; | 181 | this.contentLength = text.length; |
176 | this.props.contentEdited(text); | 182 | this.props.contentEdited(text); |
177 | }} | 183 | }} |
178 | - onKeyPress={(event)=>{ | 184 | + onKeyPress={(event) => { |
179 | if (this.contentLength >= 2000) { | 185 | if (this.contentLength >= 2000) { |
180 | Alert.alert('抱歉','超出2000字符最长限制'); | 186 | Alert.alert('抱歉','超出2000字符最长限制'); |
181 | } | 187 | } |
@@ -191,7 +197,7 @@ export default class Posting extends Component { | @@ -191,7 +197,7 @@ export default class Posting extends Component { | ||
191 | onPressTrigger={this.onPressBlurAll} | 197 | onPressTrigger={this.onPressBlurAll} |
192 | onPressSection={this.onPressSectionSelector} | 198 | onPressSection={this.onPressSectionSelector} |
193 | imageInView={this.state.showImagePicker} | 199 | imageInView={this.state.showImagePicker} |
194 | - keyblardInView={this.state.showKeyboard} | 200 | + keyboardInView={this.state.showKeyboard} |
195 | /> | 201 | /> |
196 | 202 | ||
197 | <AssertsPicker | 203 | <AssertsPicker |
@@ -31,9 +31,9 @@ export default class PostingToolBar extends Component { | @@ -31,9 +31,9 @@ export default class PostingToolBar extends Component { | ||
31 | } | 31 | } |
32 | 32 | ||
33 | render() { | 33 | render() { |
34 | - let {imageCount, selectedSectionName} = this.props; | ||
35 | - let keyboardImage = this.props.keyblardInView?require('../../images/jianpan1.png'):require('../../images/keyboard_normal.png'); | ||
36 | - let picImage = this.props.imageInView?require('../../images/pic1.png'):require('../../images/pic_normal.png') | 34 | + let {imageCount, selectedSectionName, keyboardInView, imageInView} = this.props; |
35 | + let keyboardImage = keyboardInView ? require('../../images/jianpan1.png') : require('../../images/keyboard_normal.png'); | ||
36 | + let picImage = imageInView ? require('../../images/pic1.png') : require('../../images/pic_normal.png') | ||
37 | return ( | 37 | return ( |
38 | <View style={styles.container}> | 38 | <View style={styles.container}> |
39 | <TouchableOpacity style={styles.imgIcon} onPress={() => { | 39 | <TouchableOpacity style={styles.imgIcon} onPress={() => { |
@@ -112,17 +112,23 @@ export default keyMirror({ | @@ -112,17 +112,23 @@ export default keyMirror({ | ||
112 | POSTING_BOARD_REQUEST: null, | 112 | POSTING_BOARD_REQUEST: null, |
113 | POSTING_BOARD_SUCCESS: null, | 113 | POSTING_BOARD_SUCCESS: null, |
114 | POSTING_BOARD_FAILURE: null, | 114 | POSTING_BOARD_FAILURE: null, |
115 | + | ||
115 | POSTING_BOARD_SELECTED: null, | 116 | POSTING_BOARD_SELECTED: null, |
116 | POSTING_ASSETS_SELECTED: null, | 117 | POSTING_ASSETS_SELECTED: null, |
117 | POSTING_TITLE_EDITED: null, | 118 | POSTING_TITLE_EDITED: null, |
118 | POSTING_CONTENT_EDITED: null, | 119 | POSTING_CONTENT_EDITED: null, |
120 | + | ||
119 | POSTING_POST_START: null, | 121 | POSTING_POST_START: null, |
122 | + POSTING_POST_SUCCESS: null, | ||
120 | POSTING_POST_FAILURE: null, | 123 | POSTING_POST_FAILURE: null, |
121 | - POSTING_UPLOAD_UPDATE: null, | 124 | + |
125 | + POSTING_IMAGE_UPLOAD_SUCCESS: null, | ||
122 | POSTING_POST_FINISHED: null, | 126 | POSTING_POST_FINISHED: null, |
127 | + | ||
123 | POSTING_STATE_RESET: null, | 128 | POSTING_STATE_RESET: null, |
124 | POSTING_STATE_MERGE: null, | 129 | POSTING_STATE_MERGE: null, |
125 | POSTING_EVENT_LOGOUT: null, | 130 | POSTING_EVENT_LOGOUT: null, |
131 | + | ||
126 | USER_FORBID_STATE_REQUEST: null, | 132 | USER_FORBID_STATE_REQUEST: null, |
127 | USER_FORBID_STATE_SUCCESS: null, | 133 | USER_FORBID_STATE_SUCCESS: null, |
128 | USER_FORBID_STATE_FAILURE: null, | 134 | USER_FORBID_STATE_FAILURE: null, |
@@ -159,7 +159,7 @@ class HomeContainer extends React.Component { | @@ -159,7 +159,7 @@ class HomeContainer extends React.Component { | ||
159 | } | 159 | } |
160 | 160 | ||
161 | _onPressSectionTag(section) { | 161 | _onPressSectionTag(section) { |
162 | - this.props.actions.goToSection(section, this.props.navigationState.name); | 162 | + this.props.actions.goToSection(section); |
163 | } | 163 | } |
164 | 164 | ||
165 | _onPressComment(id) { | 165 | _onPressComment(id) { |
@@ -188,10 +188,7 @@ class HomeContainer extends React.Component { | @@ -188,10 +188,7 @@ class HomeContainer extends React.Component { | ||
188 | } | 188 | } |
189 | 189 | ||
190 | _onUploadRetry() { | 190 | _onUploadRetry() { |
191 | - | ||
192 | - this.props.actions.startPosting(this.props.posting.assets.toJS()); | ||
193 | - | ||
194 | - console.log('upload retry!'); | 191 | + this.props.actions.startPosting(); |
195 | } | 192 | } |
196 | 193 | ||
197 | _onUploadDelete() { | 194 | _onUploadDelete() { |
@@ -203,10 +200,10 @@ class HomeContainer extends React.Component { | @@ -203,10 +200,10 @@ class HomeContainer extends React.Component { | ||
203 | } | 200 | } |
204 | 201 | ||
205 | render() { | 202 | render() { |
206 | - let {inPosting, postFail, finishedCount, postPercent, assets, postingBannerShow, uploadState,} = this.props.posting; | 203 | + let {postState, post} = this.props.posting; |
207 | 204 | ||
208 | - let assetsData = assets.toJS(); | ||
209 | - let percent = postPercent; | 205 | + let assetsData = post.assets.toJS(); |
206 | + let percent = postState.uploadedImagePercent; | ||
210 | let uri = ''; | 207 | let uri = ''; |
211 | if (assetsData.length) { | 208 | if (assetsData.length) { |
212 | uri = assetsData[0].uri; | 209 | uri = assetsData[0].uri; |
@@ -215,18 +212,18 @@ class HomeContainer extends React.Component { | @@ -215,18 +212,18 @@ class HomeContainer extends React.Component { | ||
215 | } | 212 | } |
216 | 213 | ||
217 | let progressing = []; | 214 | let progressing = []; |
218 | - if (postingBannerShow) { | 215 | + if (postState.showProcess) { |
219 | progressing = [{ | 216 | progressing = [{ |
220 | - uploadState,//(0发布中,1发布成功,2发布失败) | ||
221 | - progress:percent,//(0~1) | ||
222 | - image:uri, | ||
223 | - postingBannerShow, | 217 | + uploadState: postState.status, //(1发布中,2发布成功,3发布失败) |
218 | + progress: percent,//(0~1) | ||
219 | + image: uri, | ||
220 | + postingBannerShow: postState.showProcess, | ||
224 | }]; | 221 | }]; |
225 | } | 222 | } |
226 | 223 | ||
227 | progressing = Immutable.fromJS(progressing); | 224 | progressing = Immutable.fromJS(progressing); |
228 | 225 | ||
229 | - let {banner, notice, section, recommendation, ptr, sync, error, isFetching} = this.props.home; | 226 | + let {banner, notice, section, recommendation, ptr, error, isFetching} = this.props.home; |
230 | let bannerData = Immutable.fromJS([banner.list]); | 227 | let bannerData = Immutable.fromJS([banner.list]); |
231 | let noticeData = notice.open === 'Y' ? Immutable.fromJS([notice.list]) : List(); | 228 | let noticeData = notice.open === 'Y' ? Immutable.fromJS([notice.list]) : List(); |
232 | let sectionData = Immutable.fromJS([section]); | 229 | let sectionData = Immutable.fromJS([section]); |
@@ -269,7 +266,6 @@ class HomeContainer extends React.Component { | @@ -269,7 +266,6 @@ class HomeContainer extends React.Component { | ||
269 | onUploadSuccess={this._onUploadSuccess} | 266 | onUploadSuccess={this._onUploadSuccess} |
270 | onUploadRetry={this._onUploadRetry} | 267 | onUploadRetry={this._onUploadRetry} |
271 | onUploadDelete={this._onUploadDelete} | 268 | onUploadDelete={this._onUploadDelete} |
272 | - isSyncFetching={sync.isFetching} | ||
273 | onSaveingTheWorld={this._onSaveingTheWorld} | 269 | onSaveingTheWorld={this._onSaveingTheWorld} |
274 | ptrError={error} | 270 | ptrError={error} |
275 | /> | 271 | /> |
@@ -83,17 +83,9 @@ class PostingContainer extends Component{ | @@ -83,17 +83,9 @@ class PostingContainer extends Component{ | ||
83 | } | 83 | } |
84 | 84 | ||
85 | componentWillReceiveProps(nextProps) { | 85 | componentWillReceiveProps(nextProps) { |
86 | - if (this.props.posting.dataValid) { | ||
87 | - if (nextProps.posting.dataValid) { | ||
88 | - return; | ||
89 | - } | ||
90 | - Actions.refresh({key: 'Posting', rightButtonTextStyle: {color:'#a0a0a0'}}); | ||
91 | - | ||
92 | - } else { | ||
93 | - if (!nextProps.posting.dataValid) { | ||
94 | - return; | ||
95 | - } | ||
96 | - Actions.refresh({key: 'Posting', rightButtonTextStyle: {color:'white'}}); | 86 | + if (this.props.posting.canSubmit !== nextProps.posting.canSubmit) { |
87 | + let color = nextProps.posting.canSubmit ? 'white' : '#a0a0a0'; | ||
88 | + Actions.refresh({key: 'Posting', rightButtonTextStyle: {color}}); | ||
97 | } | 89 | } |
98 | } | 90 | } |
99 | 91 | ||
@@ -110,8 +102,9 @@ class PostingContainer extends Component{ | @@ -110,8 +102,9 @@ class PostingContainer extends Component{ | ||
110 | } | 102 | } |
111 | 103 | ||
112 | contentEdited(content) { | 104 | contentEdited(content) { |
113 | - this.props.actions.contentEdited (content); | 105 | + this.props.actions.contentEdited(content); |
114 | } | 106 | } |
107 | + | ||
115 | render() { | 108 | render() { |
116 | let fromSection=false; | 109 | let fromSection=false; |
117 | if (this.props.section.sid>-1) { | 110 | if (this.props.section.sid>-1) { |
@@ -119,18 +112,22 @@ class PostingContainer extends Component{ | @@ -119,18 +112,22 @@ class PostingContainer extends Component{ | ||
119 | fromSection = section.name.length && section.id>0; | 112 | fromSection = section.name.length && section.id>0; |
120 | } | 113 | } |
121 | 114 | ||
115 | + let {boards, post} = this.props.posting; | ||
116 | + post = post.toJS(); | ||
117 | + let {assets, title, content, sectionName} = post; | ||
118 | + | ||
122 | return( | 119 | return( |
123 | <View style={styles.container}> | 120 | <View style={styles.container}> |
124 | <Posting | 121 | <Posting |
125 | - boards={this.props.posting.boards.toJS()} | ||
126 | - selectedBoard={this.props.posting.currentBoardName.length?this.props.posting.currentBoardName:'请选择板块'} | 122 | + boards={boards.list.toJS()} |
123 | + selectedBoard={sectionName ? sectionName : '请选择板块'} | ||
127 | onBoardPress={this.boardSelectedWithName} | 124 | onBoardPress={this.boardSelectedWithName} |
128 | - assets={this.props.posting.assets.toJS()} | 125 | + assets={assets} |
129 | assetsSelected={this.assetsSelected} | 126 | assetsSelected={this.assetsSelected} |
130 | titleEdited={this.titleEdited} | 127 | titleEdited={this.titleEdited} |
131 | contentEdited={this.contentEdited} | 128 | contentEdited={this.contentEdited} |
132 | - titleValue={this.props.posting.title} | ||
133 | - contentValue={this.props.posting.content} | 129 | + titleValue={title} |
130 | + contentValue={content} | ||
134 | fromSection={fromSection} | 131 | fromSection={fromSection} |
135 | /> | 132 | /> |
136 | </View> | 133 | </View> |
@@ -166,36 +166,28 @@ class SectionContainer extends React.Component { | @@ -166,36 +166,28 @@ class SectionContainer extends React.Component { | ||
166 | 166 | ||
167 | render() { | 167 | render() { |
168 | 168 | ||
169 | - let { | ||
170 | - inPosting, | ||
171 | - postFail, | ||
172 | - finishedCount, | ||
173 | - postPercent, | ||
174 | - assets, | ||
175 | - postingBannerShow, | ||
176 | - uploadState, | ||
177 | - } = this.props.posting; | ||
178 | - | ||
179 | - let assetsData = assets.toJS(); | ||
180 | - let percent = postPercent; | 169 | + let {postState, post} = this.props.posting; |
170 | + | ||
171 | + let assetsData = post.assets.toJS(); | ||
172 | + let percent = postState.uploadedImagePercent; | ||
181 | let uri = ''; | 173 | let uri = ''; |
182 | if (assetsData.length) { | 174 | if (assetsData.length) { |
183 | uri = assetsData[0].uri; | 175 | uri = assetsData[0].uri; |
184 | - }else { | 176 | + } else { |
185 | percent = 1; | 177 | percent = 1; |
186 | } | 178 | } |
187 | 179 | ||
188 | let progressing = []; | 180 | let progressing = []; |
189 | - if (postingBannerShow) { | 181 | + if (postState.showProcess) { |
190 | progressing = [{ | 182 | progressing = [{ |
191 | - uploadState,//(0发布中,1发布成功,2发布失败) | ||
192 | - progress:percent,//(0~1) | ||
193 | - image:uri, | ||
194 | - postingBannerShow, | 183 | + uploadState: postState.status, //(1发布中,2发布成功,3发布失败) |
184 | + progress: percent,//(0~1) | ||
185 | + image: uri, | ||
186 | + postingBannerShow: postState.showProcess, | ||
195 | }]; | 187 | }]; |
196 | } | 188 | } |
197 | - progressing = Immutable.fromJS(progressing); | ||
198 | 189 | ||
190 | + progressing = Immutable.fromJS(progressing); | ||
199 | 191 | ||
200 | let section = this.props.section.items.get(this.sid); | 192 | let section = this.props.section.items.get(this.sid); |
201 | let {activeTab, new: newPost, hot: hotPost, header, notice, ptr, isFetching : bnsIsFetching} = section; | 193 | let {activeTab, new: newPost, hot: hotPost, header, notice, ptr, isFetching : bnsIsFetching} = section; |
@@ -35,11 +35,6 @@ let InitialState = Record({ | @@ -35,11 +35,6 @@ let InitialState = Record({ | ||
35 | list: List(), | 35 | list: List(), |
36 | endReached: false, | 36 | endReached: false, |
37 | })), | 37 | })), |
38 | - sync: new (Record({ | ||
39 | - isFetching: false, | ||
40 | - error: null, | ||
41 | - ssouid: 0, | ||
42 | - })), | ||
43 | }); | 38 | }); |
44 | 39 | ||
45 | export default InitialState; | 40 | export default InitialState; |
@@ -23,17 +23,22 @@ const { | @@ -23,17 +23,22 @@ const { | ||
23 | POSTING_BOARD_REQUEST, | 23 | POSTING_BOARD_REQUEST, |
24 | POSTING_BOARD_SUCCESS, | 24 | POSTING_BOARD_SUCCESS, |
25 | POSTING_BOARD_FAILURE, | 25 | POSTING_BOARD_FAILURE, |
26 | + | ||
26 | POSTING_BOARD_SELECTED, | 27 | POSTING_BOARD_SELECTED, |
27 | POSTING_ASSETS_SELECTED, | 28 | POSTING_ASSETS_SELECTED, |
28 | POSTING_TITLE_EDITED, | 29 | POSTING_TITLE_EDITED, |
29 | POSTING_CONTENT_EDITED, | 30 | POSTING_CONTENT_EDITED, |
31 | + | ||
30 | POSTING_POST_START, | 32 | POSTING_POST_START, |
33 | + POSTING_POST_SUCCESS, | ||
31 | POSTING_POST_FAILURE, | 34 | POSTING_POST_FAILURE, |
32 | - POSTING_UPLOAD_UPDATE, | 35 | + |
36 | + POSTING_IMAGE_UPLOAD_SUCCESS, | ||
33 | POSTING_POST_FINISHED, | 37 | POSTING_POST_FINISHED, |
34 | POSTING_STATE_RESET, | 38 | POSTING_STATE_RESET, |
35 | POSTING_STATE_MERGE, | 39 | POSTING_STATE_MERGE, |
36 | POSTING_EVENT_LOGOUT, | 40 | POSTING_EVENT_LOGOUT, |
41 | + | ||
37 | USER_FORBID_STATE_REQUEST, | 42 | USER_FORBID_STATE_REQUEST, |
38 | USER_FORBID_STATE_SUCCESS, | 43 | USER_FORBID_STATE_SUCCESS, |
39 | USER_FORBID_STATE_FAILURE, | 44 | USER_FORBID_STATE_FAILURE, |
@@ -41,6 +46,34 @@ const { | @@ -41,6 +46,34 @@ const { | ||
41 | 46 | ||
42 | let POSTING_CACHE_KEY = 'POSTING_CACHE_KEY'; | 47 | let POSTING_CACHE_KEY = 'POSTING_CACHE_KEY'; |
43 | 48 | ||
49 | + | ||
50 | +export function commitMerge(cachedObj) { | ||
51 | + return { | ||
52 | + type: POSTING_STATE_MERGE, | ||
53 | + payload: cachedObj, | ||
54 | + }; | ||
55 | +} | ||
56 | + | ||
57 | +export function mergeCachedPosting() { | ||
58 | + return dispatch => { | ||
59 | + store.get(POSTING_CACHE_KEY) | ||
60 | + .then((cachedObj)=>{ | ||
61 | + if (cachedObj) { | ||
62 | + // let canSubmit = canSubmitPost(getState(), title, null, null); | ||
63 | + dispatch(commitMerge(cachedObj)); | ||
64 | + } | ||
65 | + }) | ||
66 | + } | ||
67 | + | ||
68 | +} | ||
69 | + | ||
70 | +export function resetState() { | ||
71 | + YH_CommunityAssetsPicker.resetState(); | ||
72 | + return { | ||
73 | + type: POSTING_STATE_RESET, | ||
74 | + }; | ||
75 | +} | ||
76 | + | ||
44 | export function postingEventLogOut() { | 77 | export function postingEventLogOut() { |
45 | store.delete(POSTING_CACHE_KEY); | 78 | store.delete(POSTING_CACHE_KEY); |
46 | return { | 79 | return { |
@@ -51,7 +84,7 @@ export function postingEventLogOut() { | @@ -51,7 +84,7 @@ export function postingEventLogOut() { | ||
51 | export function startEditPost(postingState) { | 84 | export function startEditPost(postingState) { |
52 | return (dispatch, getState) => { | 85 | return (dispatch, getState) => { |
53 | let {posting, user} = getState(); | 86 | let {posting, user} = getState(); |
54 | - if (posting.inPosting) { | 87 | + if (posting.postState.isPosting) { |
55 | Alert.alert('抱歉','您有正在发送的帖子,请耐心等待~'); | 88 | Alert.alert('抱歉','您有正在发送的帖子,请耐心等待~'); |
56 | return; | 89 | return; |
57 | } | 90 | } |
@@ -106,52 +139,67 @@ export function drillToEditPostPage() { | @@ -106,52 +139,67 @@ export function drillToEditPostPage() { | ||
106 | dispatch(goToPosting()); | 139 | dispatch(goToPosting()); |
107 | } | 140 | } |
108 | }).catch(error => { | 141 | }).catch(error => { |
109 | - dispatch(userForbidStateRequest(error)); | 142 | + dispatch(userForbidStateFailure(error)); |
110 | dispatch(goToPosting()); | 143 | dispatch(goToPosting()); |
111 | - __DEV__ && console.log(error); | ||
112 | }) | 144 | }) |
113 | } | 145 | } |
114 | } | 146 | } |
115 | 147 | ||
116 | -export function commitMerge(cachedObj) { | ||
117 | - return { | ||
118 | - type: POSTING_STATE_MERGE, | ||
119 | - payload: Immutable.fromJS(cachedObj), | ||
120 | - }; | 148 | +export function titleEdited(title) { |
149 | + return (dispatch, getState) => { | ||
150 | + let canSubmit = canSubmitPost(getState(), title, null, null); | ||
151 | + dispatch({ | ||
152 | + type: POSTING_TITLE_EDITED, | ||
153 | + payload: {title, canSubmit}, | ||
154 | + }); | ||
155 | + } | ||
121 | } | 156 | } |
122 | 157 | ||
123 | -export function mergeCachedPosting() { | ||
124 | - return dispatch => { | ||
125 | - store.get(POSTING_CACHE_KEY) | ||
126 | - .then((cachedObj)=>{ | ||
127 | - if (cachedObj) { | ||
128 | - dispatch(commitMerge(cachedObj)); | ||
129 | - dispatch(startPosting(cachedObj.assets)); | ||
130 | - } | ||
131 | - }) | 158 | +export function contentEdited(content) { |
159 | + return (dispatch, getState) => { | ||
160 | + let canSubmit = canSubmitPost(getState(), null, content, null); | ||
161 | + dispatch({ | ||
162 | + type: POSTING_CONTENT_EDITED, | ||
163 | + payload: {content, canSubmit}, | ||
164 | + }); | ||
132 | } | 165 | } |
133 | - | ||
134 | } | 166 | } |
135 | 167 | ||
136 | -export function titleEdited(title) { | ||
137 | - return { | ||
138 | - type:POSTING_TITLE_EDITED, | ||
139 | - payload: title, | ||
140 | - }; | 168 | +export function boardSelected(sectionName, sectionId) { |
169 | + return (dispatch, getState) => { | ||
170 | + let canSubmit = canSubmitPost(getState(), null, null, sectionName); | ||
171 | + dispatch({ | ||
172 | + type: POSTING_BOARD_SELECTED, | ||
173 | + payload: {sectionName, sectionId, canSubmit}, | ||
174 | + }); | ||
175 | + } | ||
141 | } | 176 | } |
142 | 177 | ||
143 | -export function contentEdited(content) { | 178 | +export function assetsSelected(assets) { |
144 | return { | 179 | return { |
145 | - type: POSTING_CONTENT_EDITED, | ||
146 | - payload: content, | 180 | + type: POSTING_ASSETS_SELECTED, |
181 | + payload: assets, | ||
147 | }; | 182 | }; |
148 | } | 183 | } |
149 | 184 | ||
150 | -export function boardSelected(boardName,boardCode) { | ||
151 | - return { | ||
152 | - type: POSTING_BOARD_SELECTED, | ||
153 | - payload: {boardName, boardCode}, | ||
154 | - }; | 185 | +function canSubmitPost(state, newTitle = null, newContent = null, newSectionName = null) { |
186 | + let {posting} = state; | ||
187 | + let {post} = posting; | ||
188 | + let {title, content, sectionName} = post; | ||
189 | + | ||
190 | + let canSubmitPost = false; | ||
191 | + | ||
192 | + let titleValue = newTitle !== null ? newTitle : title; | ||
193 | + let contentValue = newContent !== null ? newContent : content; | ||
194 | + let sectionNameValue = newSectionName !== null ? newSectionName : sectionName; | ||
195 | + | ||
196 | + let hasTitleOrContent = titleValue.length > 0 || contentValue.length > 0; | ||
197 | + let hasSection = sectionNameValue.length > 0; | ||
198 | + if (hasTitleOrContent && hasSection) { | ||
199 | + canSubmitPost = true; | ||
200 | + } | ||
201 | + | ||
202 | + return canSubmitPost; | ||
155 | } | 203 | } |
156 | 204 | ||
157 | export function getBoardRequest() { | 205 | export function getBoardRequest() { |
@@ -174,27 +222,49 @@ export function getBoardFailure(error) { | @@ -174,27 +222,49 @@ export function getBoardFailure(error) { | ||
174 | }; | 222 | }; |
175 | } | 223 | } |
176 | 224 | ||
177 | -export function postStart() { | ||
178 | - return { | ||
179 | - type: POSTING_POST_START, | ||
180 | - }; | ||
181 | -} | ||
182 | - | ||
183 | -export function uploadImageStateChanged(payloadData) { | ||
184 | - return { | ||
185 | - type: POSTING_UPLOAD_UPDATE, | ||
186 | - payload:payloadData, | 225 | +export function getBoardList() { |
226 | + return dispatch => { | ||
227 | + dispatch(getBoardRequest()); | ||
228 | + new PostingService().getBoardList().then(json => { | ||
229 | + let payload = parseBoards(json); | ||
230 | + dispatch(getBoardSuccess(payload)); | ||
231 | + }).catch(error => { | ||
232 | + dispatch(getBoardFailure(error)); | ||
233 | + }); | ||
187 | }; | 234 | }; |
188 | } | 235 | } |
189 | 236 | ||
190 | -export function postFinished(success) { | ||
191 | - return { | ||
192 | - type:POSTING_POST_FINISHED, | ||
193 | - payload:success, | ||
194 | - }; | 237 | +function parseBoards(json) { |
238 | + let list = []; | ||
239 | + json && json.map((item, i) => { | ||
240 | + let {authorInfo, blocks} = item; | ||
241 | + | ||
242 | + let forumCode = item.forumCode ? item.forumCode : 0; | ||
243 | + let forumDesc = item.forumDesc ? item.forumDesc : ''; | ||
244 | + let forumName = item.forumName ? item.forumName : ''; | ||
245 | + let forumPic = item.forumPic ? item.forumPic : ''; | ||
246 | + let orderBy = item.orderBy ? item.orderBy : 0; | ||
247 | + let position = item.position ? item.position : 0; | ||
248 | + let magazineAdvertCode = item.magazineAdvertCode ? item.magazineAdvertCode : ''; | ||
249 | + let yohoAdvertCode = item.yohoAdvertCode ? item.yohoAdvertCode : ''; | ||
250 | + let section = { | ||
251 | + forumCode, | ||
252 | + forumDesc, | ||
253 | + forumName, | ||
254 | + forumPic, | ||
255 | + orderBy, | ||
256 | + position, | ||
257 | + magazineAdvertCode, | ||
258 | + yohoAdvertCode, | ||
259 | + }; | ||
260 | + list.push(section); | ||
261 | + }); | ||
262 | + | ||
263 | + return list; | ||
195 | } | 264 | } |
196 | 265 | ||
197 | -export function updateUploadState(url,fileName) { | 266 | +/* |
267 | +export function updateUploadState(url, fileName) { | ||
198 | 268 | ||
199 | return (dispatch, getState) => { | 269 | return (dispatch, getState) => { |
200 | 270 | ||
@@ -243,79 +313,177 @@ export function updateUploadState(url,fileName) { | @@ -243,79 +313,177 @@ export function updateUploadState(url,fileName) { | ||
243 | }); | 313 | }); |
244 | } | 314 | } |
245 | } | 315 | } |
316 | +*/ | ||
246 | 317 | ||
247 | -export function resetState() { | ||
248 | - YH_CommunityAssetsPicker.resetState(); | 318 | +export function postStart() { |
249 | return { | 319 | return { |
250 | - type: POSTING_STATE_RESET, | 320 | + type: POSTING_POST_START, |
321 | + }; | ||
322 | +} | ||
323 | + | ||
324 | +export function postSuccess(json) { | ||
325 | + return { | ||
326 | + type: POSTING_POST_SUCCESS, | ||
327 | + payload: json, | ||
251 | }; | 328 | }; |
252 | } | 329 | } |
253 | 330 | ||
254 | -export function postFail() { | 331 | +export function postFailure(error) { |
255 | return { | 332 | return { |
256 | type: POSTING_POST_FAILURE, | 333 | type: POSTING_POST_FAILURE, |
334 | + payload: error | ||
257 | }; | 335 | }; |
258 | } | 336 | } |
259 | 337 | ||
260 | -export function startPosting(assets) { | 338 | +export function startPosting() { |
261 | 339 | ||
262 | return (dispatch, getState) => { | 340 | return (dispatch, getState) => { |
341 | + let state = getState(); | ||
342 | + if (!shouldCommitPost(state)) { | ||
343 | + return; | ||
344 | + } | ||
345 | + | ||
346 | + let {posting} = state; | ||
347 | + let {post} = posting; | ||
348 | + let {assets} = post; | ||
349 | + assets = assets.toJS(); | ||
350 | + | ||
263 | dispatch(postStart()); | 351 | dispatch(postStart()); |
264 | 352 | ||
265 | - let storedState = getState().posting.toJS(); | 353 | + let storedState = posting.toJS(); |
266 | storedState.boards = []; | 354 | storedState.boards = []; |
267 | - storedState.postingBannerShow = true; | ||
268 | - store.save(POSTING_CACHE_KEY,storedState).then(()=>{ | ||
269 | - store.get(POSTING_CACHE_KEY).then((data)=>{ | ||
270 | - }) | 355 | + storedState.postState.isPosting = true; |
356 | + storedState.postState.status = 3; | ||
357 | + storedState.postState.showProcess = true; | ||
358 | + store.save(POSTING_CACHE_KEY, storedState) | ||
359 | + .then(() => { | ||
271 | if (assets.length) { | 360 | if (assets.length) { |
272 | - for (let i = 0; i < assets.length; i++) { | ||
273 | - let asset = assets[i] | ||
274 | - if (asset.finished) { | ||
275 | - continue; | ||
276 | - } | ||
277 | - new PostingService().uploadImageAsset(asset) | ||
278 | - .then(response => { | ||
279 | - dispatch(updateUploadState(response,asset.name)); | ||
280 | - }).catch(error => { | ||
281 | - dispatch(postFail()); | ||
282 | - }); | ||
283 | - } | 361 | + dispatch(commitImagePost()); |
284 | } else { | 362 | } else { |
285 | - NativeModules.YH_CommunityHelper.uid().then(ssouid => { | ||
286 | - let {posting} = getState(); | ||
287 | - let param = { | ||
288 | - postsTitle: posting.title, | ||
289 | - uid: ssouid, | ||
290 | - forumCode: posting.currentBoardId, | ||
291 | - contentData: posting.content, | ||
292 | - } | ||
293 | - return new PostingService().commitPost(param).then(json => { | ||
294 | - store.delete(POSTING_CACHE_KEY); | ||
295 | - dispatch(postFinished(true)); | ||
296 | - }).catch(error => { | ||
297 | - dispatch(postFinished(false)); | ||
298 | - }); | ||
299 | - }); | 363 | + dispatch(commitTextPost()); |
300 | } | 364 | } |
301 | - }); //Cache data before uploading.... | 365 | + }) |
366 | + .catch(error => { | ||
367 | + __DEV__ && console.log(error); | ||
368 | + }); | ||
302 | } | 369 | } |
303 | } | 370 | } |
304 | 371 | ||
305 | -export function getBoardList() { | ||
306 | - return dispatch => { | ||
307 | - dispatch(getBoardRequest()); | ||
308 | - new PostingService().getBoardList().then(json => { | ||
309 | - dispatch(getBoardSuccess(json)); | ||
310 | - }).catch(error => { | ||
311 | - dispatch(getBoardFailure(error)); | 372 | +function shouldCommitPost(state) { |
373 | + let {posting} = state; | ||
374 | + if (posting.canSubmit) { | ||
375 | + Actions.pop(); | ||
376 | + | ||
377 | + return true; | ||
378 | + } else { | ||
379 | + // 发布按钮: | ||
380 | + // 1.用户编辑内容时,“正文或标题”其一必须有内容,否则右上角发布icon置灰,点击文本弹窗提示请输入内容。 | ||
381 | + // 2.必须有选择的版块,否则右上角发布icon置灰,点击文本弹窗提示请选择版块。两者都没有优先提示请输入内容。 | ||
382 | + // | ||
383 | + let {post} = posting; | ||
384 | + let message = '未知'; | ||
385 | + if (!post.title && !post.content) { | ||
386 | + message = '请填写标题和内容'; | ||
387 | + } else if (!post.sectionName) { | ||
388 | + message = '请选择版块'; | ||
389 | + } | ||
390 | + | ||
391 | + Alert.alert('提示', message); | ||
392 | + | ||
393 | + return false; | ||
394 | + } | ||
395 | +} | ||
396 | + | ||
397 | +function commitTextPost() { | ||
398 | + return (dispatch, getState) => { | ||
399 | + NativeModules.YH_CommunityHelper.uid().then(uid => { | ||
400 | + let {posting} = getState(); | ||
401 | + let {post} = posting; | ||
402 | + let params = { | ||
403 | + postsTitle: post.title, | ||
404 | + uid: uid, | ||
405 | + forumCode: post.sectionId, | ||
406 | + contentData: post.content, | ||
407 | + } | ||
408 | + dispatch(commitPost(params)); | ||
312 | }); | 409 | }); |
313 | - }; | 410 | + } |
314 | } | 411 | } |
315 | 412 | ||
316 | -export function assetsSelected(assets) { | 413 | +function commitImagePost() { |
414 | + return (dispatch, getState) => { | ||
415 | + let {posting} = getState(); | ||
416 | + let {post} = posting; | ||
417 | + let {assets} = post; | ||
418 | + assets = assets.toJS(); | ||
419 | + for (let i = 0; i < assets.length; i++) { | ||
420 | + let asset = assets[i] | ||
421 | + if (asset.finished) { | ||
422 | + continue; | ||
423 | + } | ||
424 | + new PostingService().uploadImageAsset(asset) | ||
425 | + .then(json => { | ||
426 | + dispatch(uploadImageSuccess(json, i)); | ||
427 | + }).catch(error => { | ||
428 | + dispatch(postFailure(error)); | ||
429 | + }); | ||
430 | + } | ||
431 | + } | ||
432 | +} | ||
433 | + | ||
434 | +export function uploadImageStateChanged(payload) { | ||
317 | return { | 435 | return { |
318 | - type: POSTING_ASSETS_SELECTED, | ||
319 | - payload: assets, | 436 | + type: POSTING_IMAGE_UPLOAD_SUCCESS, |
437 | + payload: payload, | ||
320 | }; | 438 | }; |
321 | } | 439 | } |
440 | + | ||
441 | +function uploadImageSuccess(imageUrl, index) { | ||
442 | + return (dispatch, getState) => { | ||
443 | + let {posting, user} = getState(); | ||
444 | + let {post, postState} = posting; | ||
445 | + let {assets} = post; | ||
446 | + assets = assets.toJS(); | ||
447 | + assets[index].webURL = imageUrl; | ||
448 | + assets[index].finished = true; | ||
449 | + | ||
450 | + let uploadedImageCount = postState.uploadedImageCount; | ||
451 | + uploadedImageCount++; | ||
452 | + let uploadedImagePercent = parseFloat(uploadedImageCount) / assets.length; | ||
453 | + let payload = {assets, uploadedImageCount, uploadedImagePercent}; | ||
454 | + | ||
455 | + dispatch(uploadImageStateChanged(payload)); | ||
456 | + | ||
457 | + // 图片全部上传完成,上传帖子其他信息 | ||
458 | + if (uploadedImageCount == assets.length) { | ||
459 | + let imageStr = ''; | ||
460 | + let sizeStr = ''; | ||
461 | + for (let i = 0; i < assets.length; i++) { | ||
462 | + imageStr += assets[i].webURL + ','; | ||
463 | + sizeStr += assets[i].width + 'x' + assets[i].height +','; | ||
464 | + } | ||
465 | + let params = { | ||
466 | + postsTitle: post.title, | ||
467 | + uid: user.profile.uid, | ||
468 | + forumCode: post.sectionId, | ||
469 | + contentData: post.content, | ||
470 | + images: imageStr, | ||
471 | + sizes: sizeStr, | ||
472 | + } | ||
473 | + dispatch(commitPost(params)); | ||
474 | + } | ||
475 | + } | ||
476 | +} | ||
477 | + | ||
478 | +function commitPost(params) { | ||
479 | + return dispatch => { | ||
480 | + return new PostingService().commitPost(params) | ||
481 | + .then((json) => { | ||
482 | + store.delete(POSTING_CACHE_KEY); | ||
483 | + dispatch(postSuccess(json)); | ||
484 | + }) | ||
485 | + .catch(error => { | ||
486 | + dispatch(postFailure(error)); | ||
487 | + }); | ||
488 | + } | ||
489 | +} |
@@ -15,28 +15,48 @@ import Immutable, {List, Record} from 'immutable'; | @@ -15,28 +15,48 @@ import Immutable, {List, Record} from 'immutable'; | ||
15 | * The fields we're concerned with | 15 | * The fields we're concerned with |
16 | */ | 16 | */ |
17 | let InitialState = Record({ | 17 | let InitialState = Record({ |
18 | - | ||
19 | - isFetching: false, | ||
20 | - error: null, | ||
21 | - currentBoardName: '', | ||
22 | - currentBoardId: '', | ||
23 | - title: '', | ||
24 | - content: '', | ||
25 | - boards: List(), | ||
26 | - assets: List(), | ||
27 | - dataValid: false, //是否可以点击发送 | ||
28 | - inPosting: false,//正在上传 | ||
29 | - postFail: false, | ||
30 | - finishedCount: 0, | ||
31 | - postPercent: 0, | ||
32 | - postingBannerShow: false, | ||
33 | - uploadState: 0, | 18 | + // isFetching: false, |
19 | + // error: null, | ||
20 | + // currentBoardName: '', | ||
21 | + // currentBoardId: '', | ||
22 | + // title: '', | ||
23 | + // content: '', | ||
24 | + boards: new (Record({ | ||
25 | + isFetching: false, | ||
26 | + error: null, | ||
27 | + list: List(), | ||
28 | + })), | ||
29 | + // assets: List(), | ||
30 | + // dataValid: false, //是否可以点击发送 | ||
31 | + // inPosting: false,//正在上传 | ||
32 | + // postFail: false, | ||
33 | + // finishedCount: 0, | ||
34 | + // postPercent: 0, | ||
35 | + // postingBannerShow: false, | ||
36 | + // uploadState: 0, | ||
34 | userState: new (Record({ | 37 | userState: new (Record({ |
35 | isFetching: false, | 38 | isFetching: false, |
36 | error: null, | 39 | error: null, |
37 | forbidNickname: 'N', | 40 | forbidNickname: 'N', |
38 | forbidSpeaking: 'N', | 41 | forbidSpeaking: 'N', |
39 | })), | 42 | })), |
43 | + canSubmit: false, | ||
44 | + post: new (Record({ | ||
45 | + title: '', | ||
46 | + content: '', | ||
47 | + sectionId: 0, | ||
48 | + sectionName: '', | ||
49 | + assets: List(), | ||
50 | + })), | ||
51 | + postState: new (Record({ | ||
52 | + isPosting: false, | ||
53 | + error: null, | ||
54 | + showProcess: true, | ||
55 | + status: 0, // 0 - 未发布,1 - 发布中,2 - 发布成功,3 - 发布失败 | ||
56 | + stage: 0, // 0 - 图片上传,1 - 帖子上传 | ||
57 | + uploadedImageCount: 0, // 已上传图片数量 | ||
58 | + uploadedImagePercent: 0, // 已上传图片百分比 | ||
59 | + })), | ||
40 | }); | 60 | }); |
41 | 61 | ||
42 | export default InitialState; | 62 | export default InitialState; |
@@ -16,17 +16,22 @@ const { | @@ -16,17 +16,22 @@ const { | ||
16 | POSTING_BOARD_REQUEST, | 16 | POSTING_BOARD_REQUEST, |
17 | POSTING_BOARD_SUCCESS, | 17 | POSTING_BOARD_SUCCESS, |
18 | POSTING_BOARD_FAILURE, | 18 | POSTING_BOARD_FAILURE, |
19 | + | ||
19 | POSTING_BOARD_SELECTED, | 20 | POSTING_BOARD_SELECTED, |
20 | POSTING_ASSETS_SELECTED, | 21 | POSTING_ASSETS_SELECTED, |
21 | POSTING_TITLE_EDITED, | 22 | POSTING_TITLE_EDITED, |
22 | POSTING_CONTENT_EDITED, | 23 | POSTING_CONTENT_EDITED, |
24 | + | ||
23 | POSTING_POST_START, | 25 | POSTING_POST_START, |
26 | + POSTING_POST_SUCCESS, | ||
24 | POSTING_POST_FAILURE, | 27 | POSTING_POST_FAILURE, |
25 | - POSTING_UPLOAD_UPDATE, | 28 | + |
29 | + POSTING_IMAGE_UPLOAD_SUCCESS, | ||
26 | POSTING_POST_FINISHED, | 30 | POSTING_POST_FINISHED, |
27 | POSTING_STATE_RESET, | 31 | POSTING_STATE_RESET, |
28 | POSTING_STATE_MERGE, | 32 | POSTING_STATE_MERGE, |
29 | POSTING_EVENT_LOGOUT, | 33 | POSTING_EVENT_LOGOUT, |
34 | + | ||
30 | USER_FORBID_STATE_REQUEST, | 35 | USER_FORBID_STATE_REQUEST, |
31 | USER_FORBID_STATE_SUCCESS, | 36 | USER_FORBID_STATE_SUCCESS, |
32 | USER_FORBID_STATE_FAILURE, | 37 | USER_FORBID_STATE_FAILURE, |
@@ -45,110 +50,106 @@ export default function postingReducer(state = initialState, action) { | @@ -45,110 +50,106 @@ export default function postingReducer(state = initialState, action) { | ||
45 | switch (action.type) { | 50 | switch (action.type) { |
46 | 51 | ||
47 | case POSTING_STATE_MERGE: { | 52 | case POSTING_STATE_MERGE: { |
48 | - let nextState = initialState.merge(action.payload); | ||
49 | - return state.merge(action.payload); | 53 | + let {canSubmit, userState, post, postState} = action.payload; |
54 | + let nextState = state.set('canSubmit', canSubmit) | ||
55 | + .setIn(['userState', 'forbidNickname'], userState.forbidNickname) | ||
56 | + .setIn(['userState', 'forbidSpeaking'], userState.forbidSpeaking) | ||
57 | + .setIn(['post', 'title'], post.title) | ||
58 | + .setIn(['post', 'content'], post.content) | ||
59 | + .setIn(['post', 'sectionId'], post.sectionId) | ||
60 | + .setIn(['post', 'sectionName'], post.sectionName) | ||
61 | + .setIn(['post', 'assets'], Immutable.fromJS(post.assets)) | ||
62 | + .setIn(['postState', 'isPosting'], postState.isPosting) | ||
63 | + .setIn(['postState', 'error'], postState.error) | ||
64 | + .setIn(['postState', 'showProcess'], postState.showProcess) | ||
65 | + .setIn(['postState', 'status'], postState.status) | ||
66 | + .setIn(['postState', 'stage'], postState.stage) | ||
67 | + .setIn(['postState', 'uploadedImageCount'], postState.uploadedImageCount) | ||
68 | + .setIn(['postState', 'uploadedImagePercent'], postState.uploadedImagePercent); | ||
69 | + return nextState; | ||
50 | } | 70 | } |
51 | 71 | ||
52 | - break; | 72 | + case POSTING_EVENT_LOGOUT: |
53 | case POSTING_STATE_RESET: { | 73 | case POSTING_STATE_RESET: { |
54 | return initialState; | 74 | return initialState; |
55 | } | 75 | } |
56 | 76 | ||
57 | - break; | ||
58 | case POSTING_TITLE_EDITED: { | 77 | case POSTING_TITLE_EDITED: { |
59 | - let dataValid=false; | ||
60 | - if (action.payload.length) { | ||
61 | - dataValid = state.currentBoardName.length>0; | ||
62 | - } | ||
63 | - let nextState = state.set('title',action.payload).set('dataValid',dataValid); | 78 | + let {title, canSubmit} = action.payload; |
79 | + let nextState = state.set('canSubmit', canSubmit) | ||
80 | + .setIn(['post', 'title'], title); | ||
64 | return nextState; | 81 | return nextState; |
65 | } | 82 | } |
66 | 83 | ||
67 | - break; | ||
68 | case POSTING_CONTENT_EDITED: { | 84 | case POSTING_CONTENT_EDITED: { |
69 | - let dataValid=false; | ||
70 | - if (action.payload.length) { | ||
71 | - dataValid = state.currentBoardName.length>0; | ||
72 | - } | ||
73 | - let nextState = state.set('content',action.payload).set('dataValid',dataValid); | 85 | + let {content, canSubmit} = action.payload; |
86 | + let nextState = state.set('canSubmit', canSubmit) | ||
87 | + .setIn(['post', 'content'], content); | ||
74 | return nextState; | 88 | return nextState; |
75 | } | 89 | } |
76 | 90 | ||
77 | - break; | ||
78 | - case POSTING_BOARD_REQUEST: { | ||
79 | - let nextState = state.set('isFetching', true).set('error', null); | ||
80 | - return nextState; | ||
81 | - } | ||
82 | - break; | ||
83 | - case POSTING_BOARD_SUCCESS: { | ||
84 | - let boards = action.payload||[]; | ||
85 | - let nextState = state.set('isFetching',false) | ||
86 | - .set('error', null) | ||
87 | - .set('boards', Immutable.fromJS(boards)); | ||
88 | - return nextState; | ||
89 | - } | ||
90 | - break; | ||
91 | - case POSTING_BOARD_FAILURE: { | ||
92 | - let nextState = state.set('isFetching', false).set('error', action.payload); | ||
93 | - return nextState; | ||
94 | - } | ||
95 | - | ||
96 | - break; | ||
97 | case POSTING_BOARD_SELECTED: { | 91 | case POSTING_BOARD_SELECTED: { |
98 | - let dataValid=state.title.length>0||state.content.length>0; | ||
99 | - | ||
100 | - let nextState = state.set('currentBoardName',action.payload.boardName).set('currentBoardId',action.payload.boardCode).set('dataValid',dataValid); | 92 | + let {sectionName, sectionId, canSubmit} = action.payload; |
93 | + let nextState = state.set('canSubmit', canSubmit) | ||
94 | + .setIn(['post', 'sectionName'], sectionName) | ||
95 | + .setIn(['post', 'sectionId'], sectionId); | ||
101 | return nextState; | 96 | return nextState; |
102 | } | 97 | } |
103 | 98 | ||
104 | - break; | ||
105 | case POSTING_ASSETS_SELECTED: { | 99 | case POSTING_ASSETS_SELECTED: { |
106 | - let data = action.payload||[]; | ||
107 | - let dataValid=false; | ||
108 | - if (data.length) { | ||
109 | - dataValid = state.currentBoardName.length>0; | ||
110 | - } | ||
111 | - let nextState = state.set('assets',Immutable.fromJS(data)).set('dataValid',dataValid); | 100 | + let assets = action.payload || []; |
101 | + let nextState = state.setIn(['post', 'assets'], Immutable.fromJS(assets)); | ||
112 | return nextState; | 102 | return nextState; |
113 | } | 103 | } |
114 | 104 | ||
115 | - break; | ||
116 | - | ||
117 | case POSTING_POST_START: { | 105 | case POSTING_POST_START: { |
118 | - | ||
119 | - let nextState = state.set('inPosting',true).set('postFail',false).set('postingBannerShow',true).set('uploadState',0); | 106 | + let nextState = state.setIn(['postState', 'isPosting'], true) |
107 | + .setIn(['postState', 'error'], null) | ||
108 | + .setIn(['postState', 'showProcess'], true) | ||
109 | + .setIn(['postState', 'status'], 1); | ||
120 | return nextState; | 110 | return nextState; |
121 | } | 111 | } |
122 | 112 | ||
123 | - break; | ||
124 | - | ||
125 | - case POSTING_UPLOAD_UPDATE: { | 113 | + case POSTING_POST_SUCCESS: { |
114 | + let nextState = state.setIn(['postState', 'isPosting'], false) | ||
115 | + .setIn(['postState', 'error'], null) | ||
116 | + .setIn(['postState', 'status'], 2); | ||
117 | + return nextState; | ||
118 | + } | ||
126 | 119 | ||
127 | - let {assets,finishCount,percent} = action.payload; | ||
128 | - let nextState = state.set('assets',Immutable.fromJS(assets)) | ||
129 | - .set('finishedCount',finishCount) | ||
130 | - .set('postPercent',percent); | 120 | + case POSTING_IMAGE_UPLOAD_SUCCESS: { |
121 | + let {assets, uploadedImageCount, uploadedImagePercent} = action.payload; | ||
122 | + let nextState = state.setIn(['post', 'assets'], Immutable.fromJS(assets)) | ||
123 | + .setIn(['postState', 'uploadedImageCount'], uploadedImageCount) | ||
124 | + .setIn(['postState', 'uploadedImagePercent'], uploadedImagePercent); | ||
131 | return nextState; | 125 | return nextState; |
132 | } | 126 | } |
133 | 127 | ||
134 | - break; | ||
135 | case POSTING_POST_FAILURE: { | 128 | case POSTING_POST_FAILURE: { |
136 | - let nextState = state.set('inPosting',false).set('postFail',true).set('uploadState',2); | 129 | + let nextState = state.setIn(['postState', 'isPosting'], false) |
130 | + .setIn(['postState', 'error'], action.payload) | ||
131 | + .setIn(['postState', 'status'], 3); | ||
137 | return nextState; | 132 | return nextState; |
138 | } | 133 | } |
139 | 134 | ||
140 | - break; | ||
141 | - case POSTING_POST_FINISHED: { | ||
142 | - let success = action.payload; | ||
143 | - let upState = success?1:2 | ||
144 | - let nextState = state.set('inPosting',!success).set('postFail',!success).set('uploadState',upState); | 135 | + case POSTING_BOARD_REQUEST: { |
136 | + let nextState = state.setIn(['boards', 'isFetching'], true) | ||
137 | + .setIn(['boards', 'error'], null); | ||
138 | + return nextState; | ||
139 | + } | ||
140 | + | ||
141 | + case POSTING_BOARD_SUCCESS: { | ||
142 | + let nextState = state.setIn(['boards', 'isFetching'], false) | ||
143 | + .setIn(['boards', 'error'], null) | ||
144 | + .setIn(['boards', 'list'], Immutable.fromJS(action.payload)); | ||
145 | return nextState; | 145 | return nextState; |
146 | } | 146 | } |
147 | 147 | ||
148 | - break; | ||
149 | - case POSTING_EVENT_LOGOUT: | ||
150 | - return initialState; | ||
151 | - break; | 148 | + case POSTING_BOARD_FAILURE: { |
149 | + let nextState = state.setIn(['boards', 'isFetching'], false) | ||
150 | + .setIn(['boards', 'error'], action.payload); | ||
151 | + return nextState; | ||
152 | + } | ||
152 | 153 | ||
153 | case USER_FORBID_STATE_REQUEST: { | 154 | case USER_FORBID_STATE_REQUEST: { |
154 | let nextState = state.setIn(['userState', 'isFetching'], true) | 155 | let nextState = state.setIn(['userState', 'isFetching'], true) |
@@ -172,7 +173,6 @@ export default function postingReducer(state = initialState, action) { | @@ -172,7 +173,6 @@ export default function postingReducer(state = initialState, action) { | ||
172 | } | 173 | } |
173 | 174 | ||
174 | default: | 175 | default: |
175 | - | ||
176 | break; | 176 | break; |
177 | } | 177 | } |
178 | 178 |
@@ -181,8 +181,8 @@ export default class PostingService { | @@ -181,8 +181,8 @@ export default class PostingService { | ||
181 | async uploadImageAsset(asset) { | 181 | async uploadImageAsset(asset) { |
182 | 182 | ||
183 | let formData = new FormData(); | 183 | let formData = new FormData(); |
184 | - formData.append('project','social');//for community .... | ||
185 | - formData.append('fileData',{name:asset.name,type: 'image/jpeg','uri':asset.url}); | 184 | + formData.append('project', 'social'); |
185 | + formData.append('fileData', {name: asset.name, type: 'image/jpeg', 'uri': asset.url}); | ||
186 | 186 | ||
187 | 187 | ||
188 | let app_version = DeviceInfo.getBuildNumber(); | 188 | let app_version = DeviceInfo.getBuildNumber(); |
@@ -192,36 +192,32 @@ export default class PostingService { | @@ -192,36 +192,32 @@ export default class PostingService { | ||
192 | let screen_size = width + 'x' + height; | 192 | let screen_size = width + 'x' + height; |
193 | let privateKey = RNNativeConfig.getPrivateKey(); | 193 | let privateKey = RNNativeConfig.getPrivateKey(); |
194 | 194 | ||
195 | - formData.append('app_version',app_version); | ||
196 | - formData.append('os_version',os_version); | ||
197 | - formData.append('client_type',client_type); | ||
198 | - formData.append('screen_size',width + 'x' + height); | ||
199 | - formData.append('privateKey',privateKey); | 195 | + formData.append('app_version', app_version); |
196 | + formData.append('os_version', os_version); | ||
197 | + formData.append('client_type', client_type); | ||
198 | + formData.append('screen_size', width + 'x' + height); | ||
199 | + formData.append('privateKey', privateKey); | ||
200 | 200 | ||
201 | 201 | ||
202 | let options = {}; | 202 | let options = {}; |
203 | options.body = formData; | 203 | options.body = formData; |
204 | options.method = 'post'; | 204 | options.method = 'post'; |
205 | - options.headers = {'project':'social',HTTP_REFERER:'admin.yohobuy.com'}; | ||
206 | - console.log('zhixingdao zheli le ..............SSSSSSSSSSSSSSSSSSSSSSSS'); | ||
207 | - console.log(options); | 205 | + options.headers = {'project': 'social', HTTP_REFERER: 'admin.yohobuy.com'}; |
206 | + | ||
208 | return await fetch('http://upload.static.yohobuy.com', options) | 207 | return await fetch('http://upload.static.yohobuy.com', options) |
209 | - .then((response) => { | ||
210 | - | ||
211 | - return response.json().then( | ||
212 | - (json) => { | ||
213 | - console.log(json); | ||
214 | - if (json.code == 200) { | ||
215 | - return json.data.imagesList[0]; | ||
216 | - }else { | ||
217 | - throw(json); | 208 | + .then((response) => { |
209 | + return response.json().then( | ||
210 | + (json) => { | ||
211 | + console.log(json); | ||
212 | + if (json.code == 200) { | ||
213 | + return json.data.imagesList[0]; | ||
214 | + } else { | ||
215 | + throw(json); | ||
216 | + } | ||
218 | } | 217 | } |
219 | - } | ||
220 | - ) | ||
221 | - | ||
222 | - | ||
223 | - }).catch((error) => { | ||
224 | - throw(error); | ||
225 | - }); | 218 | + ) |
219 | + }).catch((error) => { | ||
220 | + throw(error); | ||
221 | + }); | ||
226 | } | 222 | } |
227 | } | 223 | } |
-
Please register or login to post a comment