UserSettingContainer.js 2.04 KB
'use strict';

import React from 'react';
import ReactNative from 'react-native';
import Immutable, {Map} from 'immutable';


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

import Setting from '../components/setting/Setting';

import * as userActions from '../reducers/user/userActions';

const {

    SETTING_SAVE_REQUEST,
    SETTING_SAVE_SUCCESS,
    SETTING_SAVE_FAILURE,

} = require('../constants/actionTypes').default;


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

const actions = [
    userActions,
];

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 SettingContainer extends React.Component {
    constructor(props) {
        super(props);
        this._nickNameEdited = this._nickNameEdited.bind(this);
        this._signEdited = this._signEdited.bind(this);
    }
    componentWillUnmount() {
        this.props.actions.settingClean();
    }

    _nickNameEdited(nickName) {
        this.props.actions.modifyNickName(nickName);
    }

    _signEdited(sign) {
        this.props.actions.modifySignature(sign);
    }

    render() {
        let {setting} = this.props.user;
        return (
            <View style={styles.container}>
                <Setting
                    setting={setting}
                    nickNameEdited={this._nickNameEdited}
                    signEdited={this._signEdited}
                />
            </View>
        );
    }
}


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

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

});


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