MessageContainer.js 1.91 KB
'use strict';

import React from 'react';
import ReactNative from 'react-native';

import {bindActionCreators} from 'redux';
import {connect} from 'react-redux';

import Immutable, {Map} from 'immutable';

import Message from '../components/Message';

import * as messageActions from '../reducers/message/messageActions';

const {
    Component,
} = React;

const {
    StatusBar,
    View,
    Text,
    StyleSheet,
    Dimensions,
    Platform,
} = ReactNative;

const actions = [
    messageActions
];

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 MessageContainer extends Component {

    constructor(props) {
        super(props);
        this.pressRow = this.pressRow.bind(this);
    }

    componentDidMount() {
        this.props.actions.getMsgList(this.props.home.brandId);
    }

    pressRow(rowID){
        this.props.actions.checkMessageDetail(rowID);
    }

	render() {

        return (
            <View style={styles.container}>
                <StatusBar
                    hidden={false}
                    barStyle={'light-content'}
                />
                <Message
                    items={this.props.message.messageList}
                    onPressItem={this.pressRow}
                    isFetching={this.props.message.isFetching}
                />
            </View>
        );
    }
}

let {width, height} = Dimensions.get('window');
let navbarHeight = (Platform.OS === 'android') ? 50 : 64;

let styles = StyleSheet.create({
    container: {
        top: navbarHeight,
        height: height - navbarHeight - 49,
    },

});

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