SeckillContainer.js 3.41 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 Immutable, {Map} from 'immutable';
import * as seckillActions from '../reducers/seckill/seckillActions';
import Seckill from '../components/seckill/Seckill';

const actions = [
    seckillActions,
];

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._onRefresh = this._onRefresh.bind(this);
        this._onClearTipMessage = this._onClearTipMessage.bind(this);
        this._onFocusToCurStartedActivity = this._onFocusToCurStartedActivity.bind(this);
    }

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

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

    _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);
    }

    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')];

        return (
            <Seckill
                isFetching = {isFetching}
                error = {error}
                ptr = {ptr}
                queryActivityInfo = {queryActivityInfo}
                queryProductList = {productList}
                queryRemindList = {queryRemindList}
                tipMessage = {tipMessage}
                curActivity = {curActivity}
                localServerTimeDiff = {localServerTimeDiff}
                onPressTimeItem={this._onPressTimeItem}
                onPressProductItem={this._onPressProductItem}
                onPressRemindBtn={this._onPressRemindBtn}
                onRefresh={this._onRefresh}
                onClearTipMessage={this._onClearTipMessage}
                onFocusToCurStartedActivity={this._onFocusToCurStartedActivity}
            />
        );
    }
}

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

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