bigbluebutton-Github/bigbluebutton-html5/imports/ui/components/connection-status/modal/component.jsx

259 lines
7.1 KiB
React
Raw Normal View History

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 Icon from '/imports/ui/components/connection-status/icon/component';
import Switch from '/imports/ui/components/switch/component';
import Service from '../service';
2020-04-10 01:01:46 +08:00
import Modal from '/imports/ui/components/modal/simple/component';
import { styles } from './styles';
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',
},
more: {
id: 'app.connection-status.more',
description: 'More about conectivity issues',
},
offline: {
id: 'app.connection-status.offline',
description: 'Offline user',
},
dataSaving: {
id: 'app.settings.dataSavingTab.description',
description: 'Description of data saving',
},
webcam: {
id: 'app.settings.dataSavingTab.webcam',
description: 'Webcam data saving switch',
},
screenshare: {
id: 'app.settings.dataSavingTab.screenShare',
description: 'Screenshare data saving switch',
},
2020-04-10 01:01:46 +08:00
});
const propTypes = {
closeModal: PropTypes.func.isRequired,
intl: PropTypes.shape({
formatMessage: PropTypes.func.isRequired,
}).isRequired,
};
const isConnectionStatusEmpty = (connectionStatus) => {
// Check if it's defined
if (!connectionStatus) return true;
// Check if it's an array
if (!Array.isArray(connectionStatus)) return true;
// Check if is empty
if (connectionStatus.length === 0) return true;
return false;
};
2020-04-10 01:01:46 +08:00
class ConnectionStatusComponent extends PureComponent {
constructor(props) {
super(props);
this.help = Service.getHelp();
this.state = { dataSaving: props.dataSaving };
}
handleDataSavingChange(key) {
const { dataSaving } = this.state;
dataSaving[key] = !dataSaving[key];
this.setState(dataSaving);
}
2020-05-14 21:35:25 +08:00
renderEmpty() {
const { intl } = this.props;
return (
<div
className={styles.item}
data-test="connectionStatusItemEmpty"
>
2020-05-14 21:35:25 +08:00
<div className={styles.left}>
<div className={styles.name}>
<div className={styles.text}>
{intl.formatMessage(intlMessages.empty)}
</div>
</div>
</div>
</div>
);
}
renderConnections() {
const {
connectionStatus,
intl,
} = this.props;
2020-05-14 21:35:25 +08:00
if (isConnectionStatusEmpty(connectionStatus)) return this.renderEmpty();
2020-05-14 21:35:25 +08:00
return connectionStatus.map((conn, index) => {
const dateTime = new Date(conn.timestamp);
const itemStyle = {};
itemStyle[styles.even] = (index + 1) % 2 === 0;
const textStyle = {};
textStyle[styles.offline] = conn.offline;
2020-05-14 21:35:25 +08:00
return (
<div
key={index}
className={cx(styles.item, itemStyle)}
data-test="connectionStatusItemUser"
2020-05-14 21:35:25 +08:00
>
<div className={styles.left}>
<div className={styles.avatar}>
<UserAvatar
className={cx({ [styles.initials]: conn.avatar.length === 0 })}
2020-05-14 21:35:25 +08:00
you={conn.you}
avatar={conn.avatar}
2020-05-14 21:35:25 +08:00
moderator={conn.moderator}
2020-05-15 01:33:32 +08:00
color={conn.color}
2020-05-14 21:35:25 +08:00
>
{conn.name.toLowerCase().slice(0, 2)}
</UserAvatar>
</div>
2020-05-14 21:35:25 +08:00
<div className={styles.name}>
<div
className={cx(styles.text, textStyle)}
data-test={conn.offline ? "offlineUser" : null}
>
2020-05-14 21:35:25 +08:00
{conn.name}
{conn.offline ? ` (${intl.formatMessage(intlMessages.offline)})` : null}
2020-05-14 21:35:25 +08:00
</div>
</div>
<div className={styles.status}>
<div className={styles.icon}>
<Icon level={conn.level} />
</div>
2020-05-14 21:35:25 +08:00
</div>
</div>
<div className={styles.right}>
<div className={styles.time}>
<time dateTime={dateTime}>
<FormattedTime value={dateTime} />
</time>
</div>
</div>
</div>
);
});
}
renderDataSaving() {
const {
intl,
dataSaving,
} = this.props;
const {
viewParticipantsWebcams,
viewScreenshare,
} = dataSaving;
return (
<div className={styles.dataSaving}>
<div className={styles.description}>
{intl.formatMessage(intlMessages.dataSaving)}
</div>
<div className={styles.saving}>
<label className={styles.label}>
{intl.formatMessage(intlMessages.webcam)}
</label>
<Switch
icons={false}
defaultChecked={viewParticipantsWebcams}
onChange={() => this.handleDataSavingChange('viewParticipantsWebcams')}
ariaLabelledBy="webcam"
ariaLabel={intl.formatMessage(intlMessages.webcam)}
data-test="dataSavingWebcams"
/>
</div>
<div className={styles.saving}>
<label className={styles.label}>
{intl.formatMessage(intlMessages.screenshare)}
</label>
<Switch
icons={false}
defaultChecked={viewScreenshare}
onChange={() => this.handleDataSavingChange('viewScreenshare')}
ariaLabelledBy="screenshare"
ariaLabel={intl.formatMessage(intlMessages.screenshare)}
data-test="dataSavingScreenshare"
/>
</div>
</div>
);
}
2020-04-10 01:01:46 +08:00
render() {
const {
closeModal,
intl,
} = this.props;
const { dataSaving } = this.state;
2020-04-10 01:01:46 +08:00
return (
<Modal
overlayClassName={styles.overlay}
className={styles.modal}
onRequestClose={() => closeModal(dataSaving, intl)}
2020-04-10 01:01:46 +08:00
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}>
{intl.formatMessage(intlMessages.description)}
{' '}
{this.help
&& (
<a href={this.help} target="_blank" rel="noopener noreferrer">
{`(${intl.formatMessage(intlMessages.more)})`}
</a>
)
}
2020-04-10 01:01:46 +08:00
</div>
{this.renderDataSaving()}
2020-04-10 01:01:46 +08:00
<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);