2018-02-16 18:34:25 +00:00
|
|
|
import React from 'react';
|
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
import { connect } from 'react-redux';
|
2019-03-01 16:49:11 +00:00
|
|
|
import { ViewPropTypes } from 'react-native';
|
2018-02-16 18:34:25 +00:00
|
|
|
|
2019-03-01 16:49:11 +00:00
|
|
|
import Status from './Status';
|
2018-02-16 18:34:25 +00:00
|
|
|
|
2018-07-10 13:40:32 +00:00
|
|
|
@connect((state, ownProps) => {
|
|
|
|
if (state.login.user && ownProps.id === state.login.user.id) {
|
|
|
|
return {
|
|
|
|
status: state.login.user && state.login.user.status,
|
|
|
|
offline: !state.meteor.connected
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
const user = state.activeUsers[ownProps.id];
|
|
|
|
return {
|
|
|
|
status: (user && user.status) || 'offline'
|
|
|
|
};
|
|
|
|
})
|
2018-02-16 18:34:25 +00:00
|
|
|
|
2019-03-01 16:49:11 +00:00
|
|
|
export default class StatusContainer extends React.PureComponent {
|
2018-02-16 18:34:25 +00:00
|
|
|
static propTypes = {
|
2019-03-01 16:49:11 +00:00
|
|
|
// id is a prop, but it's used only inside @connect to find for current status
|
|
|
|
id: PropTypes.string, // eslint-disable-line
|
2018-02-16 18:34:25 +00:00
|
|
|
style: ViewPropTypes.style,
|
2019-03-01 16:49:11 +00:00
|
|
|
size: PropTypes.number,
|
2018-07-10 13:40:32 +00:00
|
|
|
status: PropTypes.string,
|
2018-06-13 01:29:18 +00:00
|
|
|
offline: PropTypes.bool
|
2018-02-16 18:34:25 +00:00
|
|
|
};
|
|
|
|
|
2019-03-01 16:49:11 +00:00
|
|
|
static defaultProps = {
|
|
|
|
size: 16
|
|
|
|
}
|
|
|
|
|
2018-02-16 18:34:25 +00:00
|
|
|
get status() {
|
2018-07-10 13:40:32 +00:00
|
|
|
const { offline, status } = this.props;
|
|
|
|
if (offline) {
|
|
|
|
return 'offline';
|
2018-06-05 01:17:02 +00:00
|
|
|
}
|
2018-07-10 13:40:32 +00:00
|
|
|
return status;
|
2018-02-16 18:34:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
2019-03-01 16:49:11 +00:00
|
|
|
const { style, size } = this.props;
|
|
|
|
return <Status size={size} style={style} status={this.status} />;
|
2018-02-16 18:34:25 +00:00
|
|
|
}
|
|
|
|
}
|