Authored by 孙凯

Merge branch '5.6.0' of http://git.yoho.cn/mobile/YH_RNComponent into 5.6.0

@@ -114,7 +114,7 @@ export default class List extends Component { @@ -114,7 +114,7 @@ export default class List extends Component {
114 <Text style={styles.text}>{publish_time}</Text> 114 <Text style={styles.text}>{publish_time}</Text>
115 <Image source={require('../../image/shared_view_icon.png')} style={styles.iconThumb}resizeMode={'contain'}></Image> 115 <Image source={require('../../image/shared_view_icon.png')} style={styles.iconThumb}resizeMode={'contain'}></Image>
116 <Text style={styles.text}>{views_num}</Text> 116 <Text style={styles.text}>{views_num}</Text>
117 - <TouchableOpacity activeOpacity={1.0} style={styles.likeButton} onPress={()=>{this.props.onPressLike&&this.props.onPressLike(id, isLike)}}> 117 + <TouchableOpacity activeOpacity={1.0} style={styles.likeButton} onPress={()=>{this.props.onPressLike&&this.props.onPressLike(id, isLike, this.props.rowID)}}>
118 <Image source={likeImg}/> 118 <Image source={likeImg}/>
119 </TouchableOpacity> 119 </TouchableOpacity>
120 <TouchableOpacity activeOpacity={1.0} style={styles.shareButton} onPress={()=>{this.props.onPressShare&&this.props.onPressShare(shareParam)}}> 120 <TouchableOpacity activeOpacity={1.0} style={styles.shareButton} onPress={()=>{this.props.onPressShare&&this.props.onPressShare(shareParam)}}>
@@ -66,8 +66,8 @@ class MineGuangContainer extends Component { @@ -66,8 +66,8 @@ class MineGuangContainer extends Component {
66 ReactNative.NativeModules.YH_CommonHelper.shareWithParam(param); 66 ReactNative.NativeModules.YH_CommonHelper.shareWithParam(param);
67 } 67 }
68 68
69 - _onPressLike(article_id, isLike) {  
70 - this.props.actions.onPressLike(article_id, isLike); 69 + _onPressLike(article_id,isLike,rowID) {
  70 + this.props.actions.onPressLike(article_id,rowID);
71 } 71 }
72 72
73 _onEndReached() { 73 _onEndReached() {
@@ -64,8 +64,6 @@ export function fetchUserFavArticleList() { @@ -64,8 +64,6 @@ export function fetchUserFavArticleList() {
64 } 64 }
65 return new MineGuangService(app.serviceHost).getUserFavArticleList(params) 65 return new MineGuangService(app.serviceHost).getUserFavArticleList(params)
66 .then(json => { 66 .then(json => {
67 - console.log('------mine guang');  
68 - console.log(json);  
69 if (favArticleList && favArticleList.size) { 67 if (favArticleList && favArticleList.size) {
70 favArticleList = favArticleList.toJS(); 68 favArticleList = favArticleList.toJS();
71 } 69 }
@@ -75,8 +73,6 @@ export function fetchUserFavArticleList() { @@ -75,8 +73,6 @@ export function fetchUserFavArticleList() {
75 dispatch(fetchSimpleArticleList(json.data)) 73 dispatch(fetchSimpleArticleList(json.data))
76 }) 74 })
77 .catch(error => { 75 .catch(error => {
78 - console.log('------error');  
79 - console.log(error);  
80 dispatch(fetchUserFavArticleListFailure(error)); 76 dispatch(fetchUserFavArticleListFailure(error));
81 }) 77 })
82 } 78 }
@@ -112,16 +108,10 @@ export function fetchSimpleArticleList(favArticleList) { @@ -112,16 +108,10 @@ export function fetchSimpleArticleList(favArticleList) {
112 return new MineGuangService(app.serviceHost).getSimpleArticleList(params) 108 return new MineGuangService(app.serviceHost).getSimpleArticleList(params)
113 .then(json => { 109 .then(json => {
114 //将请求到的文章相关数据合并到favArticleList 110 //将请求到的文章相关数据合并到favArticleList
115 - console.log('------mine guang');  
116 - console.log(json);  
117 let newFavArticleList = mergeSimpleArticleToFavList(favArticleList,json.artList); 111 let newFavArticleList = mergeSimpleArticleToFavList(favArticleList,json.artList);
118 - console.log('------merged');  
119 - console.log(newFavArticleList);  
120 dispatch(updateUserFavArticleList(newFavArticleList)); 112 dispatch(updateUserFavArticleList(newFavArticleList));
121 }) 113 })
122 .catch(error => { 114 .catch(error => {
123 - console.log('------error');  
124 - console.log(error);  
125 }) 115 })
126 } 116 }
127 117
@@ -157,28 +147,28 @@ function mergeSimpleArticleToFavList(favArticleList,simpleArticleList) { @@ -157,28 +147,28 @@ function mergeSimpleArticleToFavList(favArticleList,simpleArticleList) {
157 return favArticleList; 147 return favArticleList;
158 } 148 }
159 149
160 -export function onPressLike(article_id, isLike) { 150 +export function onPressLike(article_id,rowID) {
161 return (dispatch, getState) => { 151 return (dispatch, getState) => {
162 let {app, mineGuang} = getState(); 152 let {app, mineGuang} = getState();
163 -  
164 - let likeRequest = (article_id, uid, isLike) => {  
165 - // dispatch(likeArticle({article_id, isLike}));  
166 - //  
167 - // if (isLike) {  
168 - // return new ListService(app.serviceHost).setArticleFavorite(article_id, uid)  
169 - // }else {  
170 - // return new ListService(app.serviceHost).cancleArticleFavorite(article_id, uid)  
171 - // } 153 + let {userFavArticleList} = mineGuang;
  154 + let {favArticleList} = userFavArticleList;
  155 + let likeRequest = (article_id, uid) => {
  156 + if (!favArticleList || favArticleList.size == 0) {
  157 + return;
  158 + }
  159 + let newFavArticleList = favArticleList.delete(rowID);
  160 + dispatch(updateUserFavArticleList(newFavArticleList));
  161 + return new MineGuangService(app.serviceHost).cancelFavorite({article_id,uid});
172 } 162 }
173 163
174 ReactNative.NativeModules.YH_CommonHelper.uid() 164 ReactNative.NativeModules.YH_CommonHelper.uid()
175 .then(uid => { 165 .then(uid => {
176 - likeRequest(article_id, uid, isLike); 166 + likeRequest(article_id, uid);
177 }) 167 })
178 .catch(error => { 168 .catch(error => {
179 ReactNative.NativeModules.YH_CommonHelper.login() 169 ReactNative.NativeModules.YH_CommonHelper.login()
180 .then(uid => { 170 .then(uid => {
181 - likeRequest(article_id, uid, isLike); 171 + likeRequest(article_id, uid);
182 }) 172 })
183 .catch(error => { 173 .catch(error => {
184 174
@@ -41,4 +41,19 @@ export default class MineGuangService { @@ -41,4 +41,19 @@ export default class MineGuangService {
41 throw(error); 41 throw(error);
42 }); 42 });
43 } 43 }
  44 +
  45 + async cancelFavorite(params) {
  46 + return await this.api.get({
  47 + url: '/guang/api/v1/favorite/cancelFavorite',
  48 + body: {
  49 + ...params,
  50 + }
  51 + })
  52 + .then((json) => {
  53 + return json;
  54 + })
  55 + .catch((error) => {
  56 + throw(error);
  57 + });
  58 + }
44 } 59 }