2020-04-10 01:01:46 +08:00
|
|
|
import React, { PureComponent } from 'react';
|
2020-05-14 21:35:25 +08:00
|
|
|
import { FormattedTime, defineMessages, injectIntl } from 'react-intl';
|
2020-04-10 01:01:46 +08:00
|
|
|
import PropTypes from 'prop-types';
|
2020-05-14 21:35:25 +08:00
|
|
|
import cx from 'classnames';
|
|
|
|
import UserAvatar from '/imports/ui/components/user-avatar/component';
|
|
|
|
import SlowConnection from '/imports/ui/components/slow-connection/component';
|
2020-04-10 01:01:46 +08:00
|
|
|
import Modal from '/imports/ui/components/modal/simple/component';
|
|
|
|
import { styles } from './styles';
|
|
|
|
|
2020-04-14 02:45:14 +08:00
|
|
|
const STATS = Meteor.settings.public.stats;
|
|
|
|
|
2020-04-10 01:01:46 +08:00
|
|
|
const intlMessages = defineMessages({
|
|
|
|
ariaTitle: {
|
|
|
|
id: 'app.connection-status.ariaTitle',
|
|
|
|
description: 'Connection status aria title',
|
|
|
|
},
|
|
|
|
title: {
|
|
|
|
id: 'app.connection-status.title',
|
|
|
|
description: 'Connection status title',
|
|
|
|
},
|
|
|
|
description: {
|
|
|
|
id: 'app.connection-status.description',
|
|
|
|
description: 'Connection status description',
|
|
|
|
},
|
2020-05-14 21:35:25 +08:00
|
|
|
empty: {
|
|
|
|
id: 'app.connection-status.empty',
|
|
|
|
description: 'Connection status empty',
|
|
|
|
},
|
2020-04-14 02:45:14 +08:00
|
|
|
more: {
|
|
|
|
id: 'app.connection-status.more',
|
|
|
|
description: 'More about conectivity issues',
|
|
|
|
},
|
2020-05-12 21:26:08 +08:00
|
|
|
offline: {
|
|
|
|
id: 'app.connection-status.offline',
|
|
|
|
description: 'Offline user',
|
|
|
|
},
|
2020-04-10 01:01:46 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
const propTypes = {
|
|
|
|
closeModal: PropTypes.func.isRequired,
|
|
|
|
intl: PropTypes.shape({
|
|
|
|
formatMessage: PropTypes.func.isRequired,
|
|
|
|
}).isRequired,
|
|
|
|
};
|
|
|
|
|
|
|
|
class ConnectionStatusComponent extends PureComponent {
|
2020-05-14 21:35:25 +08:00
|
|
|
renderEmpty() {
|
|
|
|
const { intl } = this.props;
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div className={styles.item}>
|
|
|
|
<div className={styles.left}>
|
|
|
|
<div className={styles.name}>
|
|
|
|
<div className={styles.text}>
|
|
|
|
{intl.formatMessage(intlMessages.empty)}
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
renderConnections() {
|
2020-05-12 21:26:08 +08:00
|
|
|
const {
|
|
|
|
connectionStatus,
|
|
|
|
intl,
|
|
|
|
} = this.props;
|
2020-05-14 21:35:25 +08:00
|
|
|
|
|
|
|
if (connectionStatus.length === 0) return this.renderEmpty();
|
|
|
|
|
|
|
|
return connectionStatus.map((conn, index) => {
|
|
|
|
const dateTime = new Date(conn.timestamp);
|
|
|
|
const itemStyle = {};
|
|
|
|
itemStyle[styles.even] = index % 2 === 0;
|
|
|
|
|
2020-05-12 21:26:08 +08:00
|
|
|
const textStyle = {};
|
|
|
|
textStyle[styles.offline] = conn.offline;
|
|
|
|
|
2020-05-14 21:35:25 +08:00
|
|
|
return (
|
|
|
|
<div
|
|
|
|
key={index}
|
|
|
|
className={cx(styles.item, itemStyle)}
|
|
|
|
>
|
|
|
|
<div className={styles.left}>
|
|
|
|
<div className={styles.avatar}>
|
|
|
|
<UserAvatar
|
|
|
|
className={styles.icon}
|
|
|
|
you={conn.you}
|
|
|
|
moderator={conn.moderator}
|
|
|
|
>
|
|
|
|
{conn.name.toLowerCase().slice(0, 2)}
|
|
|
|
</UserAvatar>
|
|
|
|
</div>
|
2020-05-12 21:26:08 +08:00
|
|
|
|
2020-05-14 21:35:25 +08:00
|
|
|
<div className={styles.name}>
|
2020-05-12 21:26:08 +08:00
|
|
|
<div className={cx(styles.text, textStyle)}>
|
2020-05-14 21:35:25 +08:00
|
|
|
{conn.name}
|
2020-05-12 21:26:08 +08:00
|
|
|
{conn.offline ? ` (${intl.formatMessage(intlMessages.offline)})` : null}
|
2020-05-14 21:35:25 +08:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div className={styles.status}>
|
|
|
|
<SlowConnection effectiveConnectionType={conn.level} />
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div className={styles.right}>
|
|
|
|
<div className={styles.time}>
|
|
|
|
<time dateTime={dateTime}>
|
|
|
|
<FormattedTime value={dateTime} />
|
|
|
|
</time>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2020-04-10 01:01:46 +08:00
|
|
|
render() {
|
|
|
|
const {
|
|
|
|
closeModal,
|
|
|
|
intl,
|
|
|
|
} = this.props;
|
|
|
|
|
|
|
|
return (
|
|
|
|
<Modal
|
|
|
|
overlayClassName={styles.overlay}
|
|
|
|
className={styles.modal}
|
|
|
|
onRequestClose={closeModal}
|
|
|
|
hideBorder
|
|
|
|
contentLabel={intl.formatMessage(intlMessages.ariaTitle)}
|
|
|
|
>
|
|
|
|
<div className={styles.container}>
|
|
|
|
<div className={styles.header}>
|
|
|
|
<h2 className={styles.title}>
|
|
|
|
{intl.formatMessage(intlMessages.title)}
|
|
|
|
</h2>
|
|
|
|
</div>
|
|
|
|
<div className={styles.description}>
|
2020-04-14 02:45:14 +08:00
|
|
|
{intl.formatMessage(intlMessages.description)}{' '}
|
|
|
|
<a href={STATS.help} target="_blank" rel="noopener noreferrer">
|
|
|
|
{`(${intl.formatMessage(intlMessages.more)})`}
|
|
|
|
</a>
|
2020-04-10 01:01:46 +08:00
|
|
|
</div>
|
|
|
|
<div className={styles.content}>
|
2020-05-14 21:35:25 +08:00
|
|
|
<div className={styles.wrapper}>
|
|
|
|
{this.renderConnections()}
|
|
|
|
</div>
|
2020-04-10 01:01:46 +08:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</Modal>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ConnectionStatusComponent.propTypes = propTypes;
|
|
|
|
|
|
|
|
export default injectIntl(ConnectionStatusComponent);
|