Authored by 盖剑秋

Store posting reviewed by redding.

@@ -59,6 +59,7 @@ import { @@ -59,6 +59,7 @@ import {
59 startPosting, 59 startPosting,
60 mergeCachedPosting, 60 mergeCachedPosting,
61 getPostUser, 61 getPostUser,
  62 + startEditPost,
62 } from './reducers/posting/postingActions'; 63 } from './reducers/posting/postingActions';
63 import PostingService from './services/PostingService'; 64 import PostingService from './services/PostingService';
64 65
@@ -101,6 +102,7 @@ export default function community(platform) { @@ -101,6 +102,7 @@ export default function community(platform) {
101 store.dispatch(setPlatform(platform)); 102 store.dispatch(setPlatform(platform));
102 store.dispatch(setContianer(contaner)); 103 store.dispatch(setContianer(contaner));
103 store.dispatch(setChannel(this.props.channel)); 104 store.dispatch(setChannel(this.props.channel));
  105 + store.dispatch(mergeCachedPosting());
104 106
105 let navBarStyle = contaner === 2 ? {backgroundColor: 'gray',} : null; 107 let navBarStyle = contaner === 2 ? {backgroundColor: 'gray',} : null;
106 let extraTitleStyle = contaner === 2 ? {color: 'black',} : null; 108 let extraTitleStyle = contaner === 2 ? {color: 'black',} : null;
@@ -276,34 +278,9 @@ export default function community(platform) { @@ -276,34 +278,9 @@ export default function community(platform) {
276 }, 278 },
277 279
278 homeOnRight(state) { 280 homeOnRight(state) {
279 - if (state.getPostingState()) {  
280 - Alert.alert('抱歉','您有正在发送的帖子,请耐心等待~');  
281 - } else {  
282 - ReactNative.NativeModules.YH_CommunityHelper.uid()  
283 - .then(uid => {  
284 - this.pushPostingWithUID(uid);  
285 - })  
286 - .catch(error => {  
287 - ReactNative.NativeModules.YH_CommunityHelper.login()  
288 - .then(uid => {  
289 - this.pushPostingWithUID(uid);  
290 - });  
291 - });  
292 - } 281 + console.log(state);
  282 + state.dispatch(startEditPost(state.getPostingState()));
293 }, 283 },
294 -  
295 - pushPostingWithUID(uid) {  
296 - new PostingService().getPostUser(uid).then(json => {  
297 - if (json.forbidSpeaking === 'Y') {  
298 - Alert.alert('抱歉','您暂时被禁言,请等待禁言解除哦~');  
299 - } else {  
300 - Actions.Posting();  
301 - }  
302 - }).catch(error => {  
303 - Actions.Posting();  
304 - })  
305 - },  
306 -  
307 /* 284 /*
308 * 自定义导航push动画 285 * 自定义导航push动画
309 * 286 *
@@ -34,6 +34,51 @@ const { @@ -34,6 +34,51 @@ const {
34 34
35 let POSTING_CACHE_KEY = 'cachedPosting'; 35 let POSTING_CACHE_KEY = 'cachedPosting';
36 36
  37 +export function voidImplementationFunc() {
  38 + return {
  39 + type:'null',
  40 + }
  41 +}
  42 +
  43 +export function startEditPost(postingState) {
  44 +
  45 + return dispatch => {
  46 + console.log('lalala');
  47 + dispatch(voidImplementationFunc());
  48 + dispatch(() => {
  49 + console.log('nononononon');
  50 + if (postingState) {
  51 + Alert.alert('抱歉','您有正在发送的帖子,请耐心等待~');
  52 + } else {
  53 + NativeModules.YH_CommunityHelper.uid()
  54 + .then(uid => {
  55 + drillToEditPostPage(uid);
  56 + })
  57 + .catch(error => {
  58 + ReactNative.NativeModules.YH_CommunityHelper.login()
  59 + .then(uid => {
  60 + drillToEditPostPage(uid);
  61 + });
  62 + });
  63 + }
  64 + })
  65 + }
  66 +
  67 +
  68 +}
  69 +
  70 +function drillToEditPostPage(uid,postingPageFunc) {
  71 + new PostingService().getPostUser(uid).then(json => {
  72 + if (json.forbidSpeaking === 'Y') {
  73 + Alert.alert('抱歉','您暂时被禁言,请等待禁言解除哦~');
  74 + } else {
  75 + Actions.Posting();
  76 + }
  77 + }).catch(error => {
  78 + Actions.Posting();
  79 + })
  80 +}
  81 +
37 export function commitMerge(cachedObj) { 82 export function commitMerge(cachedObj) {
38 return { 83 return {
39 type: POSTING_STATE_MERGE, 84 type: POSTING_STATE_MERGE,
@@ -42,12 +87,17 @@ export function commitMerge(cachedObj) { @@ -42,12 +87,17 @@ export function commitMerge(cachedObj) {
42 } 87 }
43 88
44 export function mergeCachedPosting() { 89 export function mergeCachedPosting() {
45 - return dispatch => store.get(POSTING_CACHE_KEY).then(cachedObj=>{  
46 - if (cachedObj) {  
47 - dispatch(commitMerge(cachedObj));  
48 - dispatch(startPosting(cachedObj.assets));  
49 - }  
50 - }) 90 + return dispatch => {
  91 + store.get(POSTING_CACHE_KEY)
  92 + .then((cachedObj)=>{
  93 + console.log('2222222222222222222222222');
  94 + console.log(cachedObj);
  95 + if (cachedObj) {
  96 + dispatch(commitMerge(cachedObj));
  97 + dispatch(startPosting(cachedObj.assets));
  98 + }
  99 + })
  100 + }
51 101
52 } 102 }
53 103
@@ -147,7 +197,7 @@ export function updateUploadState(url,fileName) { @@ -147,7 +197,7 @@ export function updateUploadState(url,fileName) {
147 contentData: encodeURI(posting.content), 197 contentData: encodeURI(posting.content),
148 images: imageStr, 198 images: imageStr,
149 } 199 }
150 - return new PostingService().commitPost(param).then(json => { 200 + return new PostingService().commitPost(param).then((json) => {
151 store.delete(POSTING_CACHE_KEY); 201 store.delete(POSTING_CACHE_KEY);
152 dispatch(postFinished(true)); 202 dispatch(postFinished(true));
153 }).catch(error => { 203 }).catch(error => {
@@ -178,41 +228,15 @@ export function startPosting(assets) { @@ -178,41 +228,15 @@ export function startPosting(assets) {
178 dispatch(postStart()); 228 dispatch(postStart());
179 229
180 let storedState = getState().posting.toJS(); 230 let storedState = getState().posting.toJS();
181 -  
182 - let assetsArray = storedState.assets;  
183 - let temp = [];  
184 - for (var i = 0; i < assetsArray.length; i++) {  
185 - let {  
186 - uri,  
187 - height,  
188 - width,  
189 - isStored,  
190 - url,  
191 - uti,  
192 - size,  
193 - finished,  
194 - name,  
195 - webURL,  
196 - }=assetsArray[i];  
197 -  
198 - let newAsset = {  
199 - uri,  
200 - height,  
201 - width,  
202 - isStored,  
203 - url,  
204 - uti,  
205 - size,  
206 - finished,  
207 - name,  
208 - webURL,  
209 - }  
210 - temp.push(newAsset);  
211 - }  
212 - storedState.assets = temp;  
213 storedState.boards = []; 231 storedState.boards = [];
214 - 232 + storedState.postingBannerShow = true;
215 store.save(POSTING_CACHE_KEY,storedState).then(()=>{ 233 store.save(POSTING_CACHE_KEY,storedState).then(()=>{
  234 + console.log('00000000000000000000000000');
  235 + console.log(storedState);
  236 + store.get(POSTING_CACHE_KEY).then((data)=>{
  237 + console.log('11111111111111111111');
  238 + console.log(data);
  239 + })
216 if (assets.length) { 240 if (assets.length) {
217 for (let i = 0; i < assets.length; i++) { 241 for (let i = 0; i < assets.length; i++) {
218 let asset = assets[i] 242 let asset = assets[i]
@@ -239,11 +263,9 @@ export function startPosting(assets) { @@ -239,11 +263,9 @@ export function startPosting(assets) {
239 contentData: posting.content, 263 contentData: posting.content,
240 } 264 }
241 return new PostingService().commitPost(param).then(json => { 265 return new PostingService().commitPost(param).then(json => {
242 - console.log(json);  
243 store.delete(POSTING_CACHE_KEY); 266 store.delete(POSTING_CACHE_KEY);
244 dispatch(postFinished(true)); 267 dispatch(postFinished(true));
245 }).catch(error => { 268 }).catch(error => {
246 - console.log('download error.....');  
247 dispatch(postFinished(false)); 269 dispatch(postFinished(false));
248 }); 270 });
249 }); 271 });