UserThatNotMeContainer.js 3.4 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 {Actions} from 'react-native-router-flux';
import UserThatNotMe from '../components/userThatNotMe/UserThatNotMe';
import * as userThatNotMeActions from '../reducers/userThatNotMe/userThatNotMeActions';
import {shouldShowTabBar, shouldHideTabBar} from '../utils/tabBar';

const {
    StatusBar,
    ScrollView,
    View,
    StyleSheet,
    Dimensions,
    Platform,
    ActionSheetIOS,
    InteractionManager,
} = ReactNative;

const actions = [
    userThatNotMeActions,
];

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 UserThatNotMeContainer extends React.Component {
    constructor(props) {
        super(props);

        this._onEndReached = this._onEndReached.bind(this);
    }

    componentDidMount() {
        if (shouldHideTabBar(this.props.navigationState)) {
            ReactNative.NativeModules.YH_CommunityHelper.hideTabBar();
        }
        InteractionManager.runAfterInteractions(() => {
            this.props.actions.getUserThatNotMeInfo();
        });
        this._onEndReached();
    }

    componentWillUnmount() {
        if (shouldShowTabBar(this.props.navigationState)) {
            Actions.refresh({key: 'Home', showNativeTabBar: true});
        }

        // this.props.actions.sectionClean();
    }

    _onPressAvatar(url) {
        console.log('avatar');
    }

    _onPressComment(url) {
        console.log('comment');
    }

    _onPressLike(url) {
        console.log('like');
    }

    _onPressPosts() {
        console.log('posts');
    }

    _onEndReached() {
        InteractionManager.runAfterInteractions(() => {
            this.props.actions.userThatNotMePosts();
        });
    }

    render() {
        let {profile, posts} = this.props.userThatNotMe;
        let postsData = Immutable.fromJS(posts.list);
        return (
            <View style={styles.container}>
                <UserThatNotMe
                    channel={this.props.app.channel}
                    user={profile}
                    posts={postsData}
                    isFetching={posts.isFetching}
                    endReached={posts.endReached}
                    isLoadingMore={posts.isFetching}
                    onEndReached={this._onEndReached}
                    onPressAvatar={this._onPressAvatar}
                    onPressComment={this._onPressComment}
                    onPressLike={this._onPressLike}
                    onPressReply={this._onPressReply}
                    onPressPosts={this._onPressPosts}
                    onPressUserAvatar={this._onPressUserAvatar}
                    onPressBackgroundImg={this._onPressBackgroundImg}
                />
            </View>
        );
    }

}

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

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

});

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