CategoryContainer.js 2.45 KB
'use strict'

import React, {Component} from 'react';
import ReactNative, {
    StyleSheet,
    Dimensions,
    Platform,
    View,
    Text,
    NativeModules,
    InteractionManager,
    NativeAppEventEmitter,
    Alert,
} from 'react-native'

import {bindActionCreators} from 'redux';
import {connect} from 'react-redux';
import {Map} from 'immutable';
import * as categoryActions from '../reducers/category/categoryActions';

import Category from '../components/category/Category';


const actions = [
    categoryActions,
];

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 CategoryContainer extends Component {
    constructor(props) {
        super(props);
        this._onChannelPressFliter = this._onChannelPressFliter.bind(this);
        this._pressLeftRow=this._pressLeftRow.bind(this);
        this._pressSubCateRow=this._pressSubCateRow.bind(this);
    }

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

    componentWillUnmount() {
        
    }
     _onChannelPressFliter(value){
        this.props.actions.setCurrentCateId(0);
        this.props.actions.setCurrentChannelId(value);
    }
    _pressLeftRow(value,rowID){
        this.props.actions.setCurrentCateId(rowID);
    }

    _pressSubCateRow(value){
        console.log(value);
         this.props.actions.jumpToCategory(value);
    }

    render() {
        let {
            channelFliter,
            categoryList,
            currentChannelId,
            currentCateId,
        } = this.props.category;

        return (
            <View style={styles.container}>
                <Category
                    categoryList={categoryList}
                    currentChannelId={currentChannelId}
                    currentCateId={currentCateId}
                    channelFliter= {channelFliter}
                    pressLeftRow={this._pressLeftRow}
                    onChannelPressFliter={this._onChannelPressFliter}
                    pressSubCateRow={this._pressSubCateRow}
                />
            </View>
        );
    }
}

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

});

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