2018-10-30 05:02:23 +00:00
|
|
|
/* @flow */
|
2018-03-07 00:28:19 +00:00
|
|
|
|
|
|
|
import React, { Component } from 'react';
|
|
|
|
import { connect } from 'react-redux';
|
|
|
|
|
|
|
|
import {
|
|
|
|
Avatar,
|
|
|
|
getAvatarURL,
|
|
|
|
getLocalParticipant
|
2018-05-10 23:01:55 +00:00
|
|
|
} from '../../../base/participants';
|
2018-03-07 00:28:19 +00:00
|
|
|
|
2018-10-30 05:02:23 +00:00
|
|
|
declare var interfaceConfig: Object;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The type of the React {@code Component} props of
|
|
|
|
* {@link OverflowMenuProfileItem}.
|
|
|
|
*/
|
|
|
|
type Props = {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The redux representation of the local participant.
|
|
|
|
*/
|
|
|
|
_localParticipant: Object,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Whether the button support clicking or not.
|
|
|
|
*/
|
|
|
|
_unclickable: boolean,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The callback to invoke when {@code OverflowMenuProfileItem} is
|
|
|
|
* clicked.
|
|
|
|
*/
|
|
|
|
onClick: Function
|
|
|
|
};
|
|
|
|
|
2018-03-07 00:28:19 +00:00
|
|
|
/**
|
|
|
|
* A React {@code Component} for displaying a link with a profile avatar as an
|
|
|
|
* icon.
|
|
|
|
*
|
|
|
|
* @extends Component
|
|
|
|
*/
|
2018-10-30 05:02:23 +00:00
|
|
|
class OverflowMenuProfileItem extends Component<Props> {
|
2018-03-07 00:28:19 +00:00
|
|
|
/**
|
|
|
|
* Initializes a new {@code OverflowMenuProfileItem} instance.
|
|
|
|
*
|
|
|
|
* @param {Object} props - The read-only properties with which the new
|
|
|
|
* instance is to be initialized.
|
|
|
|
*/
|
2018-10-30 05:02:23 +00:00
|
|
|
constructor(props: Props) {
|
2018-03-07 00:28:19 +00:00
|
|
|
super(props);
|
|
|
|
|
|
|
|
// Bind event handler so it is only bound once for every instance.
|
|
|
|
this._onClick = this._onClick.bind(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Implements React's {@link Component#render()}.
|
|
|
|
*
|
|
|
|
* @inheritdoc
|
|
|
|
* @returns {ReactElement}
|
|
|
|
*/
|
|
|
|
render() {
|
|
|
|
const { _localParticipant, _unclickable } = this.props;
|
|
|
|
const classNames = `overflow-menu-item ${
|
|
|
|
_unclickable ? 'unclickable' : ''}`;
|
|
|
|
const avatarURL = getAvatarURL(_localParticipant);
|
|
|
|
let displayName;
|
|
|
|
|
|
|
|
if (_localParticipant && _localParticipant.name) {
|
2018-08-22 19:35:48 +00:00
|
|
|
displayName = _localParticipant.name;
|
2018-03-07 00:28:19 +00:00
|
|
|
} else {
|
|
|
|
displayName = interfaceConfig.DEFAULT_LOCAL_DISPLAY_NAME;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
<li
|
2018-06-07 20:32:18 +00:00
|
|
|
aria-label = 'Edit your profile'
|
2018-03-07 00:28:19 +00:00
|
|
|
className = { classNames }
|
|
|
|
onClick = { this._onClick }>
|
|
|
|
<span className = 'overflow-menu-item-icon'>
|
|
|
|
<Avatar uri = { avatarURL } />
|
|
|
|
</span>
|
|
|
|
<span className = 'profile-text'>
|
|
|
|
{ displayName }
|
|
|
|
</span>
|
|
|
|
</li>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2018-10-30 05:02:23 +00:00
|
|
|
_onClick: () => void;
|
|
|
|
|
2018-03-07 00:28:19 +00:00
|
|
|
/**
|
|
|
|
* Invokes an on click callback if clicking is allowed.
|
|
|
|
*
|
|
|
|
* @returns {void}
|
|
|
|
*/
|
|
|
|
_onClick() {
|
|
|
|
if (!this.props._unclickable) {
|
|
|
|
this.props.onClick();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Maps (parts of) the Redux state to the associated
|
|
|
|
* {@code OverflowMenuProfileItem} component's props.
|
|
|
|
*
|
|
|
|
* @param {Object} state - The Redux state.
|
|
|
|
* @private
|
|
|
|
* @returns {{
|
|
|
|
* _localParticipant: Object,
|
|
|
|
* _unclickable: boolean
|
|
|
|
* }}
|
|
|
|
*/
|
|
|
|
function _mapStateToProps(state) {
|
|
|
|
return {
|
|
|
|
_localParticipant: getLocalParticipant(state),
|
|
|
|
_unclickable: !state['features/base/jwt'].isGuest
|
2018-06-20 20:19:53 +00:00
|
|
|
|| !interfaceConfig.SETTINGS_SECTIONS.includes('profile')
|
2018-03-07 00:28:19 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
export default connect(_mapStateToProps)(OverflowMenuProfileItem);
|