2018-02-16 18:34:25 +00:00
|
|
|
import React from 'react';
|
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
import { connect } from 'react-redux';
|
|
|
|
import { StyleSheet, View, ViewPropTypes } from 'react-native';
|
|
|
|
import { STATUS_COLORS } from '../constants/colors';
|
|
|
|
|
|
|
|
const styles = StyleSheet.create({
|
|
|
|
status: {
|
|
|
|
borderRadius: 16,
|
|
|
|
width: 16,
|
|
|
|
height: 16
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
@connect(state => ({
|
2018-06-05 01:17:02 +00:00
|
|
|
activeUsers: state.activeUsers,
|
|
|
|
user: state.login.user
|
2018-02-16 18:34:25 +00:00
|
|
|
}))
|
|
|
|
|
|
|
|
export default class Status extends React.Component {
|
|
|
|
static propTypes = {
|
|
|
|
style: ViewPropTypes.style,
|
|
|
|
id: PropTypes.string,
|
|
|
|
activeUsers: PropTypes.object
|
|
|
|
};
|
|
|
|
|
|
|
|
shouldComponentUpdate(nextProps) {
|
2018-06-05 01:17:02 +00:00
|
|
|
const { id: userId, user } = this.props;
|
|
|
|
if (user.id === userId) {
|
|
|
|
return (nextProps.user && nextProps.user.status !== user.status);
|
|
|
|
}
|
2018-03-29 17:55:37 +00:00
|
|
|
return (nextProps.activeUsers[userId] && nextProps.activeUsers[userId].status) !== this.status;
|
2018-02-16 18:34:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
get status() {
|
2018-06-05 01:17:02 +00:00
|
|
|
const { id: userId, user } = this.props;
|
|
|
|
if (user.id === userId) {
|
|
|
|
return user.status || 'offline';
|
|
|
|
}
|
2018-03-29 17:55:37 +00:00
|
|
|
return (this.props.activeUsers && this.props.activeUsers[userId] && this.props.activeUsers[userId].status) || 'offline';
|
2018-02-16 18:34:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
|
|
|
return (<View style={[styles.status, this.props.style, { backgroundColor: STATUS_COLORS[this.status] }]} />);
|
|
|
|
}
|
|
|
|
}
|