Authored by 张丽霞

新品到着中为您推荐,review by 盖见秋

... ... @@ -18,6 +18,7 @@ import appInitialState from './reducers/app/appInitialState';
import newArrivalInitialState from './reducers/newArrival/newArrivalInitialState';
import NewArrivalContainer from './containers/NewArrivalContainer';
import RecForYouContainer from './containers/RecForYouContainer';
import {
setPlatform,
... ... @@ -39,16 +40,24 @@ export default function native(platform) {
let YH_NewArrival = React.createClass({
render() {
let type = this.props.type;
const store = configureStore(getInitialState());
store.dispatch(setPlatform(platform));
store.dispatch(setHost(this.props.host));
store.dispatch(setServiceHost(this.props.serviceHost));
return (
<Provider store={store}>
<NewArrivalContainer />
</Provider>
);
if (type == 'recForYou' ) {
return (
<Provider store={store}>
<RecForYouContainer />
</Provider>
);
} else {
return (
<Provider store={store}>
<NewArrivalContainer />
</Provider>
);
}
}
});
... ...
... ... @@ -87,7 +87,11 @@ export default class NewArrival extends Component {
break;
case 'recommend': {
return (
<RecommendCell data={rowData} onPressShop={this.props.onPressShop}/>
<RecommendCell
data={rowData}
onPressShop={this.props.onPressShop}
goToRecommendForYou={this.props.goToRecommendForYou}
/>
)
}
break;
... ...
... ... @@ -36,7 +36,9 @@ export default class RecommendCell extends Component {
<View style={styles.container}>
<View style={styles.header}>
<Text style={styles.headerText}>为您推荐</Text>
<TouchableOpacity style={styles.moreButton} onPress={()=>{console.log('.....');}}>
<TouchableOpacity style={styles.moreButton} onPress={()=>{
this.props.goToRecommendForYou && this.props.goToRecommendForYou();
}}>
<Image style={styles.moreImage} source={require('../../image/more.png')}/>
</TouchableOpacity>
</View>
... ...
... ... @@ -55,6 +55,7 @@ class NewArrivalContainer extends Component {
this._onPressCloseMoreFilter=this._onPressCloseMoreFilter.bind(this);
this._onPressShop = this._onPressShop.bind(this);
this._onPressProductListProduct = this._onPressProductListProduct.bind(this);
this._goToRecommendForYou = this._goToRecommendForYou.bind(this);
}
componentDidMount() {
... ... @@ -127,6 +128,10 @@ class NewArrivalContainer extends Component {
}
_goToRecommendForYou() {
this.props.actions.goToRecommendForYou();
}
render() {
let {newArrival} = this.props;
... ... @@ -157,6 +162,7 @@ class NewArrivalContainer extends Component {
onPressCloseMoreFilter={this._onPressCloseMoreFilter}
onPressShop={this._onPressShop}
onPressProductListProduct={this._onPressProductListProduct}
goToRecommendForYou={this._goToRecommendForYou}
/>
</View>
);
... ...
'use strict'
import React, {Component} from 'react';
import ReactNative, {
StyleSheet,
Dimensions,
Platform,
View,
Text,
NativeModules,
InteractionManager,
NativeAppEventEmitter,
} from 'react-native'
import {bindActionCreators} from 'redux';
import {connect} from 'react-redux';
import {Map} from 'immutable';
import * as newArrivalActions from '../reducers/newArrival/newArrivalActions';
import LoadingIndicator from '../../common/components/LoadingIndicator';
import RecommendForYou from '../components/newArrival/RecommendForYou';
const actions = [
newArrivalActions,
];
function mapStateToProps(state) {
return {
...state
};
}
function mapDispatchToProps(dispatch) {
const creators = Map()
.merge(...actions)
.filter(value => typeof value === 'function')
.toObject();
return {
actions: bindActionCreators(creators, dispatch),
dispatch
};
}
class NewArrivalContainer extends Component {
constructor(props) {
super(props);
this._onPressShop = this._onPressShop.bind(this);
}
componentDidMount() {
this.props.actions.getRecommendBrand();
}
componentWillUnmount() {
}
_onPressShop(data) {
let {
shop_name,
shops_id,
} = data;
if (!shops_id||!shop_name) {
return;
}
let url = `http://m.yohobuy.com?openby:yohobuy={"action":"go.shop","params":{"shop_id":"${shops_id}","shop_template_type":"1","shop_name":"${shop_name}"}}`;
ReactNative.NativeModules.YH_CommonHelper.jumpWithUrl(url);
}
render() {
let {newArrival} = this.props;
let {recommendForYou} = newArrival;
let isFetching = recommendForYou.get('isFetching');
return (
<View style={styles.container}>
<RecommendForYou
RecommendForYou={RecommendForYou}
onPressShop={this._onPressShop}
/>
<LoadingIndicator
isVisible={isFetching}
/>
</View>
);
}
}
let styles = StyleSheet.create({
container: {
flex: 1,
},
});
export default connect(mapStateToProps, mapDispatchToProps)(NewArrivalContainer);
... ...
... ... @@ -243,6 +243,12 @@ export function getRecommendBrand() {
};
}
export function goToRecommendForYou() {
return (dispatch, getState) => {
ReactNative.NativeModules.YH_NewArrivalHelper.goToRecommendForYou();
};
}
function parseProductList(json) {
let currentPage = json && json.page ? json.page : 1;
let pageCount = json && json.page_total ? json.page_total : 0;
... ...
... ... @@ -113,11 +113,19 @@ export default function newArrivalReducer(state=initialState, action) {
return state.setIn(['productList', 'isFetching'], false)
.setIn(['productList', 'error'], action.payload);
}
case RECOMMEND_BRAND_REQUEST: {
return state.setIn(['recommendForYou', 'isFetching'], true);
}
case RECOMMEND_BRAND_SUCCESS: {
return state.setIn(['recommendForYou', 'hotBrandList'], Immutable.fromJS(action.payload.hotBrandList))
return state.setIn(['recommendForYou', 'isFetching'], false)
.setIn(['recommendForYou', 'hotBrandList'], Immutable.fromJS(action.payload.hotBrandList))
.setIn(['recommendForYou', 'browseBrandList'], Immutable.fromJS(action.payload.browseBrandList))
.setIn(['recommendForYou', 'newBrandList'], Immutable.fromJS(action.payload.newBrandList));
}
case RECOMMEND_BRAND_FAILURE: {
return state.setIn(['recommendForYou', 'isFetching'], false)
.setIn(['productList', 'error'], action.payload);
}
}
return state;
... ...