import React, { Component } from 'react'; import PropTypes from 'prop-types'; import { connect } from 'react-redux'; import { dequal } from 'dequal'; import RoomHeader from './RoomHeader'; import { withDimensions } from '../../dimensions'; import I18n from '../../i18n'; interface IRoomHeaderContainerProps { title: string; subtitle: string; type: string; prid: string; tmid: string; teamMain: boolean; usersTyping: string; status: string; statusText: string; connecting: boolean; connected: boolean; roomUserId: string; widthOffset: number; onPress(): void; width: number; height: number; parentTitle: string; isGroupChat: boolean; testID: string; } class RoomHeaderContainer extends Component { shouldComponentUpdate(nextProps: IRoomHeaderContainerProps) { const { type, title, subtitle, status, statusText, connecting, connected, onPress, usersTyping, width, height, teamMain } = this.props; if (nextProps.type !== type) { return true; } if (nextProps.title !== title) { return true; } if (nextProps.subtitle !== subtitle) { return true; } if (nextProps.status !== status) { return true; } if (nextProps.statusText !== statusText) { return true; } if (nextProps.connecting !== connecting) { return true; } if (nextProps.connected !== connected) { return true; } if (nextProps.width !== width) { return true; } if (nextProps.height !== height) { return true; } if (!dequal(nextProps.usersTyping, usersTyping)) { return true; } if (nextProps.onPress !== onPress) { return true; } if (nextProps.teamMain !== teamMain) { return true; } return false; } render() { const { title, subtitle: subtitleProp, type, teamMain, prid, tmid, widthOffset, status = 'offline', statusText, connecting, connected, usersTyping, onPress, roomUserId, width, height, parentTitle, isGroupChat, testID } = this.props; let subtitle; if (connecting) { subtitle = I18n.t('Connecting'); } else if (!connected) { subtitle = I18n.t('Waiting_for_network'); } else { subtitle = subtitleProp; } return ( ); } } const mapStateToProps = (state: any, ownProps: any) => { let statusText; let status = 'offline'; const { roomUserId, type, visitor = {}, tmid } = ownProps; if (state.meteor.connected) { if ((type === 'd' || (tmid && roomUserId)) && state.activeUsers[roomUserId]) { ({ status, statusText } = state.activeUsers[roomUserId]); } else if (type === 'l' && visitor?.status) { ({ status } = visitor); } } return { connecting: state.meteor.connecting || state.server.loading, connected: state.meteor.connected, usersTyping: state.usersTyping, status, statusText }; }; export default connect(mapStateToProps)(withDimensions(RoomHeaderContainer));