2021-07-08 13:42:07 +00:00
|
|
|
// @flow
|
|
|
|
|
|
|
|
import { createToolbarEvent, sendAnalytics } from '../../../analytics';
|
|
|
|
import { translate } from '../../../base/i18n';
|
|
|
|
import { getLocalParticipant } from '../../../base/participants';
|
|
|
|
import { connect } from '../../../base/redux';
|
|
|
|
import { AbstractButton, type AbstractButtonProps } from '../../../base/toolbox/components';
|
2022-09-27 07:10:28 +00:00
|
|
|
import { SETTINGS_TABS, openSettingsDialog } from '../../../settings';
|
2021-07-08 13:42:07 +00:00
|
|
|
|
|
|
|
import ProfileButtonAvatar from './ProfileButtonAvatar';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The type of the React {@code Component} props of {@link ProfileButton}.
|
|
|
|
*/
|
|
|
|
type Props = AbstractButtonProps & {
|
|
|
|
|
2021-11-26 15:39:34 +00:00
|
|
|
/**
|
|
|
|
* Default displayed name for local participant.
|
|
|
|
*/
|
|
|
|
_defaultLocalDisplayName: string,
|
|
|
|
|
2021-07-08 13:42:07 +00:00
|
|
|
/**
|
|
|
|
* The redux representation of the local participant.
|
|
|
|
*/
|
|
|
|
_localParticipant: Object,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Whether the button support clicking or not.
|
|
|
|
*/
|
|
|
|
_unclickable: boolean,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The redux {@code dispatch} function.
|
|
|
|
*/
|
|
|
|
dispatch: Function
|
|
|
|
};
|
|
|
|
|
|
|
|
declare var interfaceConfig: Object;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Implementation of a button for opening profile dialog.
|
|
|
|
*/
|
|
|
|
class ProfileButton extends AbstractButton<Props, *> {
|
|
|
|
accessibilityLabel = 'toolbar.accessibilityLabel.profile';
|
|
|
|
icon = ProfileButtonAvatar;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Retrieves the label.
|
|
|
|
*/
|
|
|
|
get label() {
|
2021-11-26 15:39:34 +00:00
|
|
|
const {
|
|
|
|
_defaultLocalDisplayName,
|
|
|
|
_localParticipant
|
|
|
|
} = this.props;
|
2021-07-08 13:42:07 +00:00
|
|
|
let displayName;
|
|
|
|
|
2021-11-26 15:39:34 +00:00
|
|
|
if (_localParticipant?.name) {
|
2021-07-08 13:42:07 +00:00
|
|
|
displayName = _localParticipant.name;
|
|
|
|
} else {
|
2021-11-26 15:39:34 +00:00
|
|
|
displayName = _defaultLocalDisplayName;
|
2021-07-08 13:42:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return displayName;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Required by linter due to AbstractButton overwritten prop being writable.
|
|
|
|
*
|
2021-11-04 21:10:43 +00:00
|
|
|
* @param {string} _value - The value.
|
2021-07-08 13:42:07 +00:00
|
|
|
*/
|
2021-11-04 21:10:43 +00:00
|
|
|
set label(_value) {
|
|
|
|
// Unused.
|
2021-07-08 13:42:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Retrieves the tooltip.
|
|
|
|
*/
|
|
|
|
get tooltip() {
|
|
|
|
return this.label;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Required by linter due to AbstractButton overwritten prop being writable.
|
|
|
|
*
|
2021-11-04 21:10:43 +00:00
|
|
|
* @param {string} _value - The value.
|
2021-07-08 13:42:07 +00:00
|
|
|
*/
|
2021-11-04 21:10:43 +00:00
|
|
|
set tooltip(_value) {
|
|
|
|
// Unused.
|
2021-07-08 13:42:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handles clicking / pressing the button, and opens the appropriate dialog.
|
|
|
|
*
|
|
|
|
* @protected
|
|
|
|
* @returns {void}
|
|
|
|
*/
|
|
|
|
_handleClick() {
|
2022-01-04 11:21:00 +00:00
|
|
|
const { dispatch, _unclickable } = this.props;
|
2021-07-08 13:42:07 +00:00
|
|
|
|
|
|
|
if (!_unclickable) {
|
|
|
|
sendAnalytics(createToolbarEvent('profile'));
|
|
|
|
dispatch(openSettingsDialog(SETTINGS_TABS.PROFILE));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Indicates whether the button should be disabled or not.
|
|
|
|
*
|
|
|
|
* @protected
|
|
|
|
* @returns {void}
|
|
|
|
*/
|
|
|
|
_isDisabled() {
|
|
|
|
return this.props._unclickable;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Function that maps parts of Redux state tree into component props.
|
|
|
|
*
|
|
|
|
* @param {Object} state - Redux state.
|
|
|
|
* @returns {Object}
|
|
|
|
*/
|
|
|
|
const mapStateToProps = state => {
|
2021-11-26 15:39:34 +00:00
|
|
|
const { defaultLocalDisplayName } = state['features/base/config'];
|
|
|
|
|
2021-07-08 13:42:07 +00:00
|
|
|
return {
|
2021-11-26 15:39:34 +00:00
|
|
|
_defaultLocalDisplayName: defaultLocalDisplayName,
|
2021-07-08 13:42:07 +00:00
|
|
|
_localParticipant: getLocalParticipant(state),
|
|
|
|
_unclickable: !interfaceConfig.SETTINGS_SECTIONS.includes('profile'),
|
|
|
|
customClass: 'profile-button-avatar'
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
export default translate(connect(mapStateToProps)(ProfileButton));
|