OutletContainer.js 3.61 KB
'use strict'

import React, {Component} from 'react';
import ReactNative, {
    StyleSheet,
    Platform,
    InteractionManager,
    NativeAppEventEmitter,
} from 'react-native'

import {bindActionCreators} from 'redux';
import {connect} from 'react-redux';
import {Map} from 'immutable';
import * as outletActions from '../reducers/outlet/outletActions';
import Outlet from '../components/outlet/Outlet';

const actions = [
    outletActions,
];

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 OutletContainer extends Component {
    constructor(props) {
        super(props);
        this._getOutletHomeResource = this._getOutletHomeResource.bind(this);
        this._onPressProduct = this._onPressProduct.bind(this);
        this._onPressProductListProduct = this._onPressProductListProduct.bind(this);
        this._onPressFilter = this._onPressFilter.bind(this);
        this._getOutletActivityList = this._getOutletActivityList.bind(this);
        this._onEndReached = this._onEndReached.bind(this);
        this._setActivityFliter = this._setActivityFliter.bind(this);
    }

    componentDidMount() {
        this.props.actions.getCategory();
    }

    componentWillUnmount() {

    }

    _onEndReached(content_code,categoryNavigationItem) {
        let list = categoryNavigationItem?categoryNavigationItem.list:null;
        if (categoryNavigationItem) {
            this.props.actions.getProductList(content_code,categoryNavigationItem);
        }
    }

    _getOutletHomeResource(content_code,ptr){
        this.props.actions.getOutletHomeResource(content_code,ptr);
    }

    _getOutletActivityList(content_code){
        this.props.actions.getOutletActivityList(content_code);
    }

    _setActivityFliter(content_code,activityMore) {
        this.props.actions.setActivityFliter(content_code,activityMore);
    }

    _onPressProduct(url){
        ReactNative.NativeModules.YH_CommonHelper.jumpWithUrl(url);
    }

    _onPressProductListProduct(product) {
      let productSkn = product && product.get('product_skn', 0);
      if (!productSkn) {
          return;
      }
      let url = `http://m.yohobuy.com?openby:yohobuy={"action":"go.productDetail","params":{"product_skn":"${productSkn}"}}`;
      ReactNative.NativeModules.YH_CommonHelper.jumpWithUrl(url);
    }


    _onPressFilter(content_code,value,categoryNavigationItem){
        this.props.actions.onPressFilter(content_code,value);
        let list = categoryNavigationItem.list;
        if (!list) {
            this.props.actions.getProductList(content_code,categoryNavigationItem);
        }
    }

    render() {

        let {
            categoryList,
        } = this.props.outlet;

        return (
            <Outlet
                categoryList = {categoryList}
                getOutletHomeResource = {this._getOutletHomeResource}
                setActivityFliter = {this._setActivityFliter}
                getOutletActivityList = {this._getOutletActivityList}
                onPressProduct = {this._onPressProduct}
                onPressProductListProduct = {this._onPressProductListProduct}
                onPressFilter = {this._onPressFilter}
                onEndReached = {this._onEndReached}
            />
        );
    }
}

let styles = StyleSheet.create({
    container: {
        flex: 1,
    },
});

export default connect(mapStateToProps, mapDispatchToProps)(OutletContainer);