SeckillContainer.js 4.13 KB
'use strict'

import React, {Component} from "react";
import {StyleSheet, Dimensions, Platform, View, NativeModules} from "react-native";
import {bindActionCreators} from "redux";
import {connect} from "react-redux";
import {Map} from "immutable";
import * as seckillActions from "../reducers/seckill/seckillActions";
import * as discountProductActions from "../reducers/discountProduct/DiscountProductActions";
import Seckill from "../components/seckill/Seckill";

const actions = [
    seckillActions,
    discountProductActions
];

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 SeckillContainer extends Component {
    constructor(props) {
        super(props);
        this._onPressTimeItem = this._onPressTimeItem.bind(this);
        this._onPressProductItem = this._onPressProductItem.bind(this);
        this._onPressRemindBtn = this._onPressRemindBtn.bind(this);
        this._onPressGuangShopWithURL = this._onPressGuangShopWithURL.bind(this);
        this._onRefresh = this._onRefresh.bind(this);
        this._onClearTipMessage = this._onClearTipMessage.bind(this);
        this._onFocusToCurStartedActivity = this._onFocusToCurStartedActivity.bind(this);
        this._onFetchDiscountProductList = this._onFetchDiscountProductList.bind(this);
    }

    _onPressTimeItem(activity) {
        this.props.actions.clickActivityTimeItem(activity);
    }

    _onPressProductItem(product) {
        this.props.actions.clickProductItem(product);
    }

    _onPressGuangShopWithURL(url) {
        if (url && url.length) {
            NativeModules.YH_CommonHelper.jumpWithUrl(url);
        }
    }

    _onPressRemindBtn(product) {
        this.props.actions.clickRemindBtn(product);
    }

    _onRefresh(activityId) {
        this.props.actions.refreshList(activityId);
    }

    _onClearTipMessage() {
        this.props.actions.clearTipMessage();
    }

    _onFocusToCurStartedActivity(activity) {
        if (this.props.seckill.ptr) {
            return;
        }
        this.props.actions.clickActivityTimeItem(activity);
        // this.props.actions.getSeckillQueryActivity(activity.startTime / 1000);
    }

    _onFetchDiscountProductList() {
        this.props.actions.getDiscountProductList()
    }


    render() {

        let {
            isFetching,
            error,
            queryActivityInfo,
            queryProductList,
            queryRemindList,
            tipMessage,
            ptr,
            curActivity,
            localServerTimeDiff,
        } = this.props.seckill;
        if (queryProductList) {
            queryProductList = queryProductList.toJS();
        }
        let productList = queryProductList[curActivity.get('activityId')];
        let discountProduct = this.props.discountProduct;
        return (
            <Seckill
                isFetching={isFetching}
                error={error}
                ptr={ptr}
                queryActivityInfo={queryActivityInfo}
                queryProductList={productList}
                queryRemindList={queryRemindList}
                tipMessage={tipMessage}
                curActivity={curActivity}
                discountProduct={discountProduct}
                localServerTimeDiff={localServerTimeDiff}
                onPressTimeItem={this._onPressTimeItem}
                onPressProductItem={this._onPressProductItem}
                onPressRemindBtn={this._onPressRemindBtn}
                onPressGuangShopWithURL={this._onPressGuangShopWithURL}
                onRefresh={this._onRefresh}
                onFetchDiscountProductList={this._onFetchDiscountProductList}
                onClearTipMessage={this._onClearTipMessage}
                onFocusToCurStartedActivity={this._onFocusToCurStartedActivity}
            />
        );
    }
}

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

});
export default connect(mapStateToProps, mapDispatchToProps)(SeckillContainer);