2018-12-21 10:55:35 +00:00
|
|
|
import React, { Component } from 'react';
|
2018-10-31 18:40:08 +00:00
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
import { connect } from 'react-redux';
|
|
|
|
import { responsive } from 'react-native-responsive-ui';
|
|
|
|
import equal from 'deep-equal';
|
|
|
|
|
2019-04-08 12:35:28 +00:00
|
|
|
import Header from './Header';
|
2019-04-17 17:01:03 +00:00
|
|
|
import RightButtons from './RightButtons';
|
2019-12-11 23:01:12 +00:00
|
|
|
import { withTheme } from '../../../theme';
|
|
|
|
import RoomHeaderLeft from './RoomHeaderLeft';
|
2020-02-19 19:43:47 +00:00
|
|
|
import { getUserSelector } from '../../../selectors/login';
|
2018-10-31 18:40:08 +00:00
|
|
|
|
2019-08-20 19:24:22 +00:00
|
|
|
class RoomHeaderView extends Component {
|
2018-10-31 18:40:08 +00:00
|
|
|
static propTypes = {
|
|
|
|
title: PropTypes.string,
|
|
|
|
type: PropTypes.string,
|
2019-04-08 12:35:28 +00:00
|
|
|
prid: PropTypes.string,
|
2019-04-17 17:01:03 +00:00
|
|
|
tmid: PropTypes.string,
|
2019-10-07 20:56:30 +00:00
|
|
|
usersTyping: PropTypes.string,
|
2018-10-31 18:40:08 +00:00
|
|
|
window: PropTypes.object,
|
2019-04-17 17:01:03 +00:00
|
|
|
status: PropTypes.string,
|
2019-04-30 19:31:51 +00:00
|
|
|
connecting: PropTypes.bool,
|
2019-12-11 23:01:12 +00:00
|
|
|
theme: PropTypes.string,
|
|
|
|
widthOffset: PropTypes.number,
|
|
|
|
goRoomActionsView: PropTypes.func
|
2018-10-31 18:40:08 +00:00
|
|
|
};
|
|
|
|
|
2019-10-07 20:56:30 +00:00
|
|
|
shouldComponentUpdate(nextProps) {
|
2018-12-21 10:55:35 +00:00
|
|
|
const {
|
2019-12-11 23:01:12 +00:00
|
|
|
type, title, status, window, connecting, goRoomActionsView, usersTyping, theme
|
2018-12-21 10:55:35 +00:00
|
|
|
} = this.props;
|
2019-12-11 23:01:12 +00:00
|
|
|
if (nextProps.theme !== theme) {
|
|
|
|
return true;
|
|
|
|
}
|
2018-12-21 10:55:35 +00:00
|
|
|
if (nextProps.type !== type) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if (nextProps.title !== title) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if (nextProps.status !== status) {
|
|
|
|
return true;
|
|
|
|
}
|
2019-04-30 19:31:51 +00:00
|
|
|
if (nextProps.connecting !== connecting) {
|
|
|
|
return true;
|
|
|
|
}
|
2018-12-21 10:55:35 +00:00
|
|
|
if (nextProps.window.width !== window.width) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if (nextProps.window.height !== window.height) {
|
|
|
|
return true;
|
|
|
|
}
|
2019-10-07 20:56:30 +00:00
|
|
|
if (!equal(nextProps.usersTyping, usersTyping)) {
|
2019-04-29 16:03:52 +00:00
|
|
|
return true;
|
|
|
|
}
|
2019-12-11 23:01:12 +00:00
|
|
|
if (nextProps.goRoomActionsView !== goRoomActionsView) {
|
|
|
|
return true;
|
|
|
|
}
|
2018-12-21 10:55:35 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-10-31 18:40:08 +00:00
|
|
|
render() {
|
|
|
|
const {
|
2019-12-11 23:01:12 +00:00
|
|
|
window, title, type, prid, tmid, widthOffset, status = 'offline', connecting, usersTyping, goRoomActionsView, theme
|
2018-10-31 18:40:08 +00:00
|
|
|
} = this.props;
|
|
|
|
|
|
|
|
return (
|
2019-04-08 12:35:28 +00:00
|
|
|
<Header
|
|
|
|
prid={prid}
|
2019-04-17 17:01:03 +00:00
|
|
|
tmid={tmid}
|
2019-04-08 12:35:28 +00:00
|
|
|
title={title}
|
|
|
|
type={type}
|
|
|
|
status={status}
|
|
|
|
width={window.width}
|
|
|
|
height={window.height}
|
2019-12-11 23:01:12 +00:00
|
|
|
theme={theme}
|
2019-04-08 12:35:28 +00:00
|
|
|
usersTyping={usersTyping}
|
2019-04-17 17:01:03 +00:00
|
|
|
widthOffset={widthOffset}
|
2019-12-11 23:01:12 +00:00
|
|
|
goRoomActionsView={goRoomActionsView}
|
2019-04-30 19:31:51 +00:00
|
|
|
connecting={connecting}
|
2019-04-08 12:35:28 +00:00
|
|
|
/>
|
2018-10-31 18:40:08 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
2019-04-17 17:01:03 +00:00
|
|
|
|
2019-08-20 19:24:22 +00:00
|
|
|
const mapStateToProps = (state, ownProps) => {
|
|
|
|
let status;
|
|
|
|
const { rid, type } = ownProps;
|
|
|
|
if (type === 'd') {
|
2020-02-19 19:43:47 +00:00
|
|
|
const user = getUserSelector(state);
|
|
|
|
if (user.id) {
|
|
|
|
const userId = rid.replace(user.id, '').trim();
|
2019-10-07 20:56:30 +00:00
|
|
|
status = state.activeUsers[userId];
|
2019-08-20 19:24:22 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return {
|
|
|
|
connecting: state.meteor.connecting,
|
2019-10-07 20:56:30 +00:00
|
|
|
usersTyping: state.usersTyping,
|
2019-08-20 19:24:22 +00:00
|
|
|
status
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2019-12-11 23:01:12 +00:00
|
|
|
export default responsive(connect(mapStateToProps)(withTheme(RoomHeaderView)));
|
2019-08-20 19:24:22 +00:00
|
|
|
|
2019-12-11 23:01:12 +00:00
|
|
|
export { RightButtons, RoomHeaderLeft };
|