ContentMessageContainer.js 5.62 KB
/**
 * Created by zzz on 2019/3/5.
 */

'use strict'

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

import {bindActionCreators} from "redux";
import {connect} from "react-redux";
import {Map} from "immutable";
import * as contentActions from "../reducers/content/contentActions";

import ContentMessageView from '../components/content/ContentMessageView';

const actions = [
    contentActions,
]

function mapStateToProps(state) {
    return {
        tabButtons: state.content.contentType.get('list').toJS(),
        commentList: state.content.commentList.get('list').toJS(),
        isPullToRefresh: state.content.commentList.get('isPullToRefresh'),
        contentTipFlag: state.content.contentTipFlag,
        tipMessage: state.content.tipMessage,
        communityHost: state.app.communityHost,
    };
}

function mapDispatchToProps(dispatch) {

    const creators = Map()
        .merge(...actions)
        .filter(value => typeof value === 'function')
        .toObject();

    return {
        actions: bindActionCreators(creators, dispatch),
        dispatch
    };
}

class ContentMessageContainer extends Component {
    constructor(props) {
        super(props);

        this.state = {
          dataSource : {},
        };

        this._onRefresh = this._onRefresh.bind(this);
        this._onEndReached = this._onEndReached.bind(this);
        this._onHiddenTipMessage = this._onHiddenTipMessage.bind(this);
        this._jumpToShowKeyboard = this._jumpToShowKeyboard.bind(this);
        this._jumpToPersonalGrassPage = this._jumpToPersonalGrassPage.bind(this);
        this._jumpToGrassDetailPage = this._jumpToGrassDetailPage.bind(this);
    }

    componentDidMount() {
      this.props.actions.getContentList(true, 4)
      this.props.actions.getContentType()
    }

    componentWillUnmount() {
      this.props.actions.clearCommentMessageList()
    }


    _onRefresh() {
      this.props.actions.getContentList(true, 4)
      this.props.actions.getContentType()
    }

    _onEndReached() {
      this.props.actions.getContentList(false, 4)
    }

    _addArticleCommentAction(addValue) {

      let addType = this.state.dataSource.businessType === 1003 ? 1 : 0;
      let destId = addType === 0 ? this.state.dataSource.articleId : null;
      let commentId = addType === 0 ? null : this.state.dataSource.parentCommentId;
      let columnType = addType === 0 ? 1001 : null;

      this.props.actions.addArticleCommentAction(addValue, destId, commentId, addType, columnType);
    }

    _onHiddenTipMessage() {
      this.props.actions.hiddenTipMessage();
    }

    _jumpToShowKeyboard(dataSource) {
      this.setState({
        dataSource: dataSource,
      });

      NativeModules.YH_CommonHelper.showkeyBoardView(dataSource.userName).then(replyValue => {
            this._addArticleCommentAction(replyValue);
        });
    }

    //跳转到种草H5
    _jumpToPersonalGrassPage(rowData) {

       let {communityHost} = this.props

       let url = communityHost + (Platform.OS === 'ios' ? '/grass': '') + `/author/${1}/${rowData.optUid}`
       let action, params;
       if(Platform.OS === 'ios') {
           action = 'go.h5hn';
           params = {
               url,
               headerid: -1,
           }
       } else {
           action = 'go.h5';
           params = {
               url,
               param : { headerid: "-1" }
           }
       }
       let jumpParams = {
           action,
           params
       }
       let path = 'http://m.yohobuy.com?openby:yohobuy=' + JSON.stringify(jumpParams);
       NativeModules.YH_CommonHelper.jumpWithUrl(path);
    }

    _jumpToGrassDetailPage(rowData) {

       let {communityHost} = this.props

       let url = communityHost + '/grass/article' + `/detail/${rowData.articleId}`
       let action, params;
       if(Platform.OS === 'ios') {
           action = 'go.h5hn';
           params = {
               url,
               headerid: -1,
           }
       } else {
           action = 'go.h5';
           params = {
               url,
               param : { headerid: "-1" }
           }
       }
       let jumpParams = {
           action,
           params
       }
       let path = 'http://m.yohobuy.com?openby:yohobuy=' + JSON.stringify(jumpParams);
       NativeModules.YH_CommonHelper.jumpWithUrl(path);
    }

    render() {
        let {
            contentTipFlag,
            tipMessage,
            tabButtons,
            commentList,
            isPullToRefresh
        } = this.props

        return (
            <View style={styles.container}>
                <ContentMessageView
                    ref={(view) => {
                        this.messageView = view
                    }}
                    contentTipFlag={contentTipFlag}
                    tabButtons={tabButtons}
                    commentList={commentList}
                    isPullToRefresh={isPullToRefresh}
                    tipMessage={tipMessage}
                    onRefresh={this._onRefresh}
                    onEndReached={this._onEndReached}
                    onHiddenTipMessage={this._onHiddenTipMessage}
                    jumpToShowKeyboard={this._jumpToShowKeyboard}
                    jumpToPersonalGrassPage={this._jumpToPersonalGrassPage}
                    jumpToGrassDetailPage={this._jumpToGrassDetailPage}
                />
            </View>
        )
    }
}

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

export default connect(mapStateToProps, mapDispatchToProps, null, {withRef: true})(ContentMessageContainer)