verdnatura-chat/app/views/RoomView/Header/index.js

95 lines
2.1 KiB
JavaScript
Raw Normal View History

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';
2018-10-31 18:40:08 +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,
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,
connecting: PropTypes.bool,
widthOffset: PropTypes.number
2018-10-31 18:40:08 +00:00
};
shouldComponentUpdate(nextProps) {
const { usersTyping } = this.props;
const {
type, title, status, window, connecting
} = this.props;
if (nextProps.type !== type) {
return true;
}
if (nextProps.title !== title) {
return true;
}
if (nextProps.status !== status) {
return true;
}
if (nextProps.connecting !== connecting) {
return true;
}
if (nextProps.window.width !== window.width) {
return true;
}
if (nextProps.window.height !== window.height) {
return true;
}
if (!equal(nextProps.usersTyping, usersTyping)) {
2019-04-29 16:03:52 +00:00
return true;
}
return false;
}
2018-10-31 18:40:08 +00:00
render() {
const {
window, title, type, prid, tmid, widthOffset, status = 'offline', connecting, usersTyping
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}
usersTyping={usersTyping}
2019-04-17 17:01:03 +00:00
widthOffset={widthOffset}
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
const mapStateToProps = (state, ownProps) => {
let status;
const { rid, type } = ownProps;
if (type === 'd') {
if (state.login.user && state.login.user.id) {
const { id: loggedUserId } = state.login.user;
const userId = rid.replace(loggedUserId, '').trim();
status = state.activeUsers[userId];
}
}
return {
connecting: state.meteor.connecting,
usersTyping: state.usersTyping,
status
};
};
export default responsive(connect(mapStateToProps)(RoomHeaderView));
2019-04-17 17:01:03 +00:00
export { RightButtons };