2022-09-06 17:32:20 +00:00
|
|
|
/* eslint-disable lines-around-comment */
|
2022-09-13 07:36:00 +00:00
|
|
|
import { Theme } from '@mui/material';
|
|
|
|
import { ClassNameMap, withStyles } from '@mui/styles';
|
2022-03-11 13:00:49 +00:00
|
|
|
import clsx from 'clsx';
|
2021-07-13 06:50:08 +00:00
|
|
|
import React, { Component } from 'react';
|
2022-08-08 09:36:06 +00:00
|
|
|
import { WithTranslation } from 'react-i18next';
|
2022-09-13 07:36:00 +00:00
|
|
|
import { connect } from 'react-redux';
|
2021-07-13 06:50:08 +00:00
|
|
|
|
2022-09-07 08:20:05 +00:00
|
|
|
import { createReactionMenuEvent, createToolbarEvent } from '../../../analytics/AnalyticsEvents';
|
|
|
|
import { sendAnalytics } from '../../../analytics/functions';
|
2022-09-05 11:24:13 +00:00
|
|
|
import { IState, IStore } from '../../../app/types';
|
2021-09-21 17:30:24 +00:00
|
|
|
import { isMobileBrowser } from '../../../base/environment/utils';
|
2022-08-08 09:36:06 +00:00
|
|
|
import { translate } from '../../../base/i18n/functions';
|
2022-09-06 17:32:20 +00:00
|
|
|
import { raiseHand } from '../../../base/participants/actions';
|
|
|
|
import { getLocalParticipant, hasRaisedHand } from '../../../base/participants/functions';
|
|
|
|
import GifsMenu from '../../../gifs/components/web/GifsMenu';
|
2022-06-08 07:44:47 +00:00
|
|
|
// @ts-ignore
|
2022-09-06 17:32:20 +00:00
|
|
|
import GifsMenuButton from '../../../gifs/components/web/GifsMenuButton';
|
2022-03-11 13:00:49 +00:00
|
|
|
import { isGifEnabled, isGifsMenuOpen } from '../../../gifs/functions';
|
2022-06-08 07:44:47 +00:00
|
|
|
// @ts-ignore
|
2021-07-13 06:50:08 +00:00
|
|
|
import { dockToolbox } from '../../../toolbox/actions.web';
|
2021-07-20 11:31:49 +00:00
|
|
|
import { addReactionToBuffer } from '../../actions.any';
|
2021-07-13 06:50:08 +00:00
|
|
|
import { toggleReactionsMenuVisibility } from '../../actions.web';
|
2021-12-13 13:51:05 +00:00
|
|
|
import { REACTIONS, REACTIONS_MENU_HEIGHT } from '../../constants';
|
2021-07-13 06:50:08 +00:00
|
|
|
|
2022-06-08 07:44:47 +00:00
|
|
|
// @ts-ignore
|
2021-07-13 06:50:08 +00:00
|
|
|
import ReactionButton from './ReactionButton';
|
|
|
|
|
2022-08-08 09:36:06 +00:00
|
|
|
interface Props extends WithTranslation {
|
2021-07-13 06:50:08 +00:00
|
|
|
|
|
|
|
/**
|
2021-11-04 21:10:43 +00:00
|
|
|
* Docks the toolbox.
|
2021-07-13 06:50:08 +00:00
|
|
|
*/
|
2022-09-08 09:52:36 +00:00
|
|
|
_dockToolbox: Function;
|
2021-07-13 06:50:08 +00:00
|
|
|
|
2022-03-11 13:00:49 +00:00
|
|
|
/**
|
|
|
|
* Whether or not the GIF feature is enabled.
|
|
|
|
*/
|
2022-09-08 09:52:36 +00:00
|
|
|
_isGifEnabled: boolean;
|
2022-03-11 13:00:49 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Whether or not the GIF menu is visible.
|
|
|
|
*/
|
2022-09-08 09:52:36 +00:00
|
|
|
_isGifMenuVisible: boolean;
|
2022-03-11 13:00:49 +00:00
|
|
|
|
2021-07-13 06:50:08 +00:00
|
|
|
/**
|
2021-09-21 17:30:24 +00:00
|
|
|
* Whether or not it's a mobile browser.
|
2021-07-13 06:50:08 +00:00
|
|
|
*/
|
2022-09-08 09:52:36 +00:00
|
|
|
_isMobile: boolean;
|
2021-07-13 06:50:08 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The ID of the local participant.
|
|
|
|
*/
|
2022-09-14 07:54:56 +00:00
|
|
|
_localParticipantID?: string;
|
2021-07-13 06:50:08 +00:00
|
|
|
|
2021-09-21 17:30:24 +00:00
|
|
|
/**
|
|
|
|
* Whether or not the local participant's hand is raised.
|
|
|
|
*/
|
2022-09-08 09:52:36 +00:00
|
|
|
_raisedHand: boolean;
|
2021-09-21 17:30:24 +00:00
|
|
|
|
2021-12-13 13:51:05 +00:00
|
|
|
/**
|
|
|
|
* An object containing the CSS classes.
|
|
|
|
*/
|
2022-09-13 07:36:00 +00:00
|
|
|
classes: ClassNameMap<string>;
|
2021-12-13 13:51:05 +00:00
|
|
|
|
2021-07-13 06:50:08 +00:00
|
|
|
/**
|
|
|
|
* The Redux Dispatch function.
|
|
|
|
*/
|
2022-09-08 09:52:36 +00:00
|
|
|
dispatch: Function;
|
2021-07-13 06:50:08 +00:00
|
|
|
|
|
|
|
/**
|
2021-09-21 17:30:24 +00:00
|
|
|
* Whether or not it's displayed in the overflow menu.
|
2021-07-13 06:50:08 +00:00
|
|
|
*/
|
2022-09-13 07:36:00 +00:00
|
|
|
overflowMenu?: boolean;
|
2022-08-08 09:36:06 +00:00
|
|
|
}
|
2021-07-13 06:50:08 +00:00
|
|
|
|
2022-07-19 10:36:02 +00:00
|
|
|
const styles = (theme: Theme) => {
|
2021-12-13 13:51:05 +00:00
|
|
|
return {
|
|
|
|
overflow: {
|
|
|
|
width: 'auto',
|
|
|
|
paddingBottom: 'max(env(safe-area-inset-bottom, 0), 16px)',
|
|
|
|
backgroundColor: theme.palette.ui01,
|
|
|
|
boxShadow: 'none',
|
|
|
|
borderRadius: 0,
|
2022-09-13 07:36:00 +00:00
|
|
|
position: 'relative' as const,
|
|
|
|
boxSizing: 'border-box' as const,
|
2021-12-13 13:51:05 +00:00
|
|
|
height: `${REACTIONS_MENU_HEIGHT}px`
|
|
|
|
}
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2021-07-13 06:50:08 +00:00
|
|
|
/**
|
|
|
|
* Implements the reactions menu.
|
|
|
|
*
|
|
|
|
* @returns {ReactElement}
|
|
|
|
*/
|
|
|
|
class ReactionsMenu extends Component<Props> {
|
|
|
|
/**
|
|
|
|
* Initializes a new {@code ReactionsMenu} instance.
|
|
|
|
*
|
|
|
|
* @param {Props} props - The read-only React {@code Component} props with
|
|
|
|
* which the new instance is to be initialized.
|
|
|
|
*/
|
|
|
|
constructor(props: Props) {
|
|
|
|
super(props);
|
|
|
|
|
|
|
|
this._onToolbarToggleRaiseHand = this._onToolbarToggleRaiseHand.bind(this);
|
|
|
|
this._getReactionButtons = this._getReactionButtons.bind(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Implements React Component's componentDidMount.
|
|
|
|
*
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
|
|
|
componentDidMount() {
|
|
|
|
this.props._dockToolbox(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Implements React Component's componentWillUnmount.
|
|
|
|
*
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
|
|
|
componentWillUnmount() {
|
|
|
|
this.props._dockToolbox(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates an analytics toolbar event and dispatches an action for toggling
|
|
|
|
* raise hand.
|
|
|
|
*
|
|
|
|
* @returns {void}
|
|
|
|
*/
|
|
|
|
_onToolbarToggleRaiseHand() {
|
2021-08-31 11:00:27 +00:00
|
|
|
const { dispatch, _raisedHand } = this.props;
|
2021-08-23 09:57:56 +00:00
|
|
|
|
2021-07-13 06:50:08 +00:00
|
|
|
sendAnalytics(createToolbarEvent(
|
|
|
|
'raise.hand',
|
2021-08-23 09:57:56 +00:00
|
|
|
{ enable: !_raisedHand }));
|
2021-07-13 06:50:08 +00:00
|
|
|
this._doToggleRaiseHand();
|
2021-08-23 09:57:56 +00:00
|
|
|
dispatch(toggleReactionsMenuVisibility());
|
2021-07-13 06:50:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Dispatches an action to toggle the local participant's raised hand state.
|
|
|
|
*
|
|
|
|
* @private
|
|
|
|
* @returns {void}
|
|
|
|
*/
|
|
|
|
_doToggleRaiseHand() {
|
2021-10-21 09:40:57 +00:00
|
|
|
const { _raisedHand } = this.props;
|
|
|
|
|
|
|
|
this.props.dispatch(raiseHand(!_raisedHand));
|
2021-07-13 06:50:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the emoji reaction buttons.
|
|
|
|
*
|
|
|
|
* @returns {Array}
|
|
|
|
*/
|
|
|
|
_getReactionButtons() {
|
|
|
|
const { t, dispatch } = this.props;
|
2021-07-20 11:31:49 +00:00
|
|
|
let modifierKey = 'Alt';
|
|
|
|
|
|
|
|
if (window.navigator?.platform) {
|
|
|
|
if (window.navigator.platform.indexOf('Mac') !== -1) {
|
|
|
|
modifierKey = '⌥';
|
|
|
|
}
|
|
|
|
}
|
2021-07-13 06:50:08 +00:00
|
|
|
|
|
|
|
return Object.keys(REACTIONS).map(key => {
|
|
|
|
/**
|
|
|
|
* Sends reaction message.
|
|
|
|
*
|
|
|
|
* @returns {void}
|
|
|
|
*/
|
2021-07-20 11:31:49 +00:00
|
|
|
function doSendReaction() {
|
|
|
|
dispatch(addReactionToBuffer(key));
|
|
|
|
sendAnalytics(createReactionMenuEvent(key));
|
2021-07-13 06:50:08 +00:00
|
|
|
}
|
|
|
|
|
2022-06-08 07:44:47 +00:00
|
|
|
// @ts-ignore
|
2021-07-13 06:50:08 +00:00
|
|
|
return (<ReactionButton
|
|
|
|
accessibilityLabel = { t(`toolbar.accessibilityLabel.${key}`) }
|
|
|
|
icon = { REACTIONS[key].emoji }
|
|
|
|
key = { key }
|
2022-07-11 12:30:37 +00:00
|
|
|
// eslint-disable-next-line react/jsx-no-bind
|
2021-07-20 11:31:49 +00:00
|
|
|
onClick = { doSendReaction }
|
2021-07-13 06:50:08 +00:00
|
|
|
toggled = { false }
|
2021-07-20 11:31:49 +00:00
|
|
|
tooltip = { `${t(`toolbar.${key}`)} (${modifierKey} + ${REACTIONS[key].shortcutChar})` } />);
|
2021-07-13 06:50:08 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Implements React's {@link Component#render}.
|
|
|
|
*
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
|
|
|
render() {
|
2022-03-11 13:00:49 +00:00
|
|
|
const { _raisedHand, t, overflowMenu, _isMobile, classes, _isGifMenuVisible, _isGifEnabled } = this.props;
|
2021-07-13 06:50:08 +00:00
|
|
|
|
|
|
|
return (
|
2022-03-11 13:00:49 +00:00
|
|
|
<div
|
|
|
|
className = { clsx('reactions-menu', _isGifEnabled && 'with-gif',
|
|
|
|
overflowMenu && `overflow ${classes.overflow}`) }>
|
|
|
|
{_isGifEnabled && _isGifMenuVisible && <GifsMenu />}
|
2021-09-14 08:15:03 +00:00
|
|
|
<div className = 'reactions-row'>
|
2021-07-13 06:50:08 +00:00
|
|
|
{ this._getReactionButtons() }
|
2022-03-11 13:00:49 +00:00
|
|
|
{_isGifEnabled && <GifsMenuButton />}
|
2021-09-14 08:15:03 +00:00
|
|
|
</div>
|
2021-09-21 17:30:24 +00:00
|
|
|
{_isMobile && (
|
|
|
|
<div className = 'raise-hand-row'>
|
2022-06-08 07:44:47 +00:00
|
|
|
{/* @ts-ignore */}
|
2021-09-21 17:30:24 +00:00
|
|
|
<ReactionButton
|
|
|
|
accessibilityLabel = { t('toolbar.accessibilityLabel.raiseHand') }
|
|
|
|
icon = '✋'
|
|
|
|
key = 'raisehand'
|
|
|
|
label = {
|
|
|
|
`${t(`toolbar.${_raisedHand ? 'lowerYourHand' : 'raiseYourHand'}`)}
|
|
|
|
${overflowMenu ? '' : ' (R)'}`
|
|
|
|
}
|
|
|
|
onClick = { this._onToolbarToggleRaiseHand }
|
|
|
|
toggled = { true } />
|
|
|
|
</div>
|
|
|
|
)}
|
2021-07-13 06:50:08 +00:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Function that maps parts of Redux state tree into component props.
|
|
|
|
*
|
|
|
|
* @param {Object} state - Redux state.
|
|
|
|
* @returns {Object}
|
|
|
|
*/
|
2022-09-05 11:24:13 +00:00
|
|
|
function mapStateToProps(state: IState) {
|
2021-07-13 06:50:08 +00:00
|
|
|
const localParticipant = getLocalParticipant(state);
|
|
|
|
|
|
|
|
return {
|
2022-09-14 07:54:56 +00:00
|
|
|
_localParticipantID: localParticipant?.id,
|
2021-09-21 17:30:24 +00:00
|
|
|
_isMobile: isMobileBrowser(),
|
2022-03-11 13:00:49 +00:00
|
|
|
_isGifEnabled: isGifEnabled(state),
|
|
|
|
_isGifMenuVisible: isGifsMenuOpen(state),
|
2021-10-21 09:40:57 +00:00
|
|
|
_raisedHand: hasRaisedHand(localParticipant)
|
2021-07-13 06:50:08 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Function that maps parts of Redux actions into component props.
|
|
|
|
*
|
|
|
|
* @param {Object} dispatch - Redux dispatch.
|
|
|
|
* @returns {Object}
|
|
|
|
*/
|
2022-06-08 07:44:47 +00:00
|
|
|
function mapDispatchToProps(dispatch: IStore['dispatch']) {
|
2021-07-13 06:50:08 +00:00
|
|
|
return {
|
|
|
|
dispatch,
|
2022-09-14 07:54:56 +00:00
|
|
|
_dockToolbox: (dock: boolean) => dispatch(dockToolbox(dock))
|
2021-07-13 06:50:08 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
export default translate(connect(
|
|
|
|
mapStateToProps,
|
2021-11-04 21:10:43 +00:00
|
|
|
mapDispatchToProps
|
2021-12-13 13:51:05 +00:00
|
|
|
)(withStyles(styles)(ReactionsMenu)));
|