2017-06-04 10:40:14 +08:00
|
|
|
import React, { Component } from 'react';
|
|
|
|
import PropTypes from 'prop-types';
|
2016-07-06 00:54:45 +08:00
|
|
|
import Icon from '/imports/ui/components/icon/component';
|
2016-06-01 04:25:42 +08:00
|
|
|
import styles from './styles.scss';
|
|
|
|
import cx from 'classnames';
|
2016-11-23 01:38:40 +08:00
|
|
|
import generateColor from './color-generator';
|
2016-06-01 04:25:42 +08:00
|
|
|
|
2016-06-02 21:00:57 +08:00
|
|
|
const propTypes = {
|
2017-06-04 10:40:14 +08:00
|
|
|
user: PropTypes.shape({
|
|
|
|
name: PropTypes.string.isRequired,
|
|
|
|
isPresenter: PropTypes.bool.isRequired,
|
|
|
|
isVoiceUser: PropTypes.bool.isRequired,
|
|
|
|
isModerator: PropTypes.bool.isRequired,
|
|
|
|
isOnline: PropTypes.bool.isRequired,
|
|
|
|
image: PropTypes.string,
|
2016-06-02 21:00:57 +08:00
|
|
|
}).isRequired,
|
|
|
|
};
|
|
|
|
|
|
|
|
const defaultProps = {
|
|
|
|
};
|
|
|
|
|
2016-06-01 04:25:42 +08:00
|
|
|
export default class UserAvatar extends Component {
|
|
|
|
render() {
|
2016-07-09 03:09:16 +08:00
|
|
|
const {
|
2016-08-21 09:14:12 +08:00
|
|
|
user,
|
2016-07-09 03:09:16 +08:00
|
|
|
} = this.props;
|
2016-07-05 04:44:29 +08:00
|
|
|
|
2017-04-12 03:46:51 +08:00
|
|
|
const avatarColor = user.isOnline ? generateColor(user.name) : '#fff';
|
2016-11-23 01:38:40 +08:00
|
|
|
|
2017-06-03 03:25:02 +08:00
|
|
|
const avatarStyles = {
|
2016-11-23 01:38:40 +08:00
|
|
|
backgroundColor: avatarColor,
|
|
|
|
boxShadow: user.isTalking ? `0 0 .5rem ${avatarColor}` : 'none',
|
2016-07-05 04:44:29 +08:00
|
|
|
};
|
2016-06-02 21:00:57 +08:00
|
|
|
|
|
|
|
return (
|
2017-06-03 03:25:02 +08:00
|
|
|
<div
|
|
|
|
className={user.isOnline ? styles.userAvatar : styles.userLogout}
|
|
|
|
style={avatarStyles} aria-hidden="true"
|
|
|
|
>
|
2017-04-17 21:34:11 +08:00
|
|
|
<div>
|
2016-07-06 00:54:45 +08:00
|
|
|
{this.renderAvatarContent()}
|
2017-04-17 21:34:11 +08:00
|
|
|
</div>
|
2016-07-09 03:09:16 +08:00
|
|
|
{this.renderUserStatus()}
|
|
|
|
{this.renderUserMediaStatus()}
|
2016-06-01 04:25:42 +08:00
|
|
|
</div>
|
2016-06-02 21:00:57 +08:00
|
|
|
);
|
2016-06-01 04:25:42 +08:00
|
|
|
}
|
2016-07-06 00:54:45 +08:00
|
|
|
|
|
|
|
renderAvatarContent() {
|
2016-07-09 03:09:16 +08:00
|
|
|
const user = this.props.user;
|
2016-07-06 00:54:45 +08:00
|
|
|
|
2017-07-08 03:12:35 +08:00
|
|
|
let content = <span aria-hidden="true" className={styles.avatarText}>{user.name.slice(0, 2)}</span>;
|
2016-07-06 00:54:45 +08:00
|
|
|
|
2016-08-21 09:14:12 +08:00
|
|
|
if (user.emoji.status !== 'none') {
|
2017-06-03 03:25:02 +08:00
|
|
|
let iconEmoji;
|
2017-04-06 22:42:01 +08:00
|
|
|
|
|
|
|
switch (user.emoji.status) {
|
|
|
|
case 'thumbsUp':
|
|
|
|
iconEmoji = 'thumbs_up';
|
|
|
|
break;
|
|
|
|
case 'thumbsDown':
|
|
|
|
iconEmoji = 'thumbs_down';
|
|
|
|
break;
|
|
|
|
case 'raiseHand':
|
|
|
|
iconEmoji = 'hand';
|
|
|
|
break;
|
|
|
|
case 'away':
|
|
|
|
iconEmoji = 'time';
|
|
|
|
break;
|
|
|
|
case 'neutral':
|
|
|
|
iconEmoji = 'undecided';
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
iconEmoji = user.emoji.status;
|
|
|
|
}
|
2017-06-03 03:25:02 +08:00
|
|
|
content = <span aria-label={user.emoji.status}><Icon iconName={iconEmoji} /></span>;
|
2016-07-06 00:54:45 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return content;
|
|
|
|
}
|
2016-07-09 03:09:16 +08:00
|
|
|
|
|
|
|
renderUserStatus() {
|
|
|
|
const user = this.props.user;
|
|
|
|
let userStatus;
|
|
|
|
|
2017-06-03 03:25:02 +08:00
|
|
|
const userStatusClasses = {};
|
2016-07-09 03:09:16 +08:00
|
|
|
userStatusClasses[styles.moderator] = user.isModerator;
|
|
|
|
userStatusClasses[styles.presenter] = user.isPresenter;
|
|
|
|
|
|
|
|
if (user.isModerator || user.isPresenter) {
|
|
|
|
userStatus = (
|
2017-06-03 03:25:02 +08:00
|
|
|
<span className={cx(styles.userStatus, userStatusClasses)} />
|
2016-07-09 03:09:16 +08:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
return userStatus;
|
|
|
|
}
|
|
|
|
|
|
|
|
renderUserMediaStatus() {
|
|
|
|
const user = this.props.user;
|
|
|
|
let userMediaStatus;
|
|
|
|
|
2017-06-03 03:25:02 +08:00
|
|
|
const userMediaClasses = {};
|
2016-07-09 03:09:16 +08:00
|
|
|
userMediaClasses[styles.voiceOnly] = user.isListenOnly;
|
|
|
|
userMediaClasses[styles.microphone] = user.isVoiceUser;
|
|
|
|
|
|
|
|
if (user.isListenOnly || user.isVoiceUser) {
|
|
|
|
userMediaStatus = (
|
|
|
|
<span className={cx(styles.userMediaStatus, userMediaClasses)}>
|
2017-06-03 03:25:02 +08:00
|
|
|
{user.isMuted ? <div className={styles.microphoneMuted} /> : null}
|
2016-07-09 03:09:16 +08:00
|
|
|
</span>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
return userMediaStatus;
|
|
|
|
}
|
2016-06-01 04:25:42 +08:00
|
|
|
}
|
2016-06-02 21:00:57 +08:00
|
|
|
|
|
|
|
UserAvatar.propTypes = propTypes;
|
|
|
|
UserAvatar.defaultProps = defaultProps;
|