2022-09-05 11:24:13 +00:00
|
|
|
/* eslint-disable lines-around-comment */
|
2021-11-04 21:10:43 +00:00
|
|
|
import React, { useCallback } from 'react';
|
2022-08-08 09:36:06 +00:00
|
|
|
import { WithTranslation } from 'react-i18next';
|
2022-04-13 13:18:54 +00:00
|
|
|
import { useSelector } from 'react-redux';
|
2022-09-05 11:24:13 +00:00
|
|
|
|
|
|
|
import { IState } 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 { IconArrowUp } from '../../../base/icons/svg';
|
2022-07-27 09:56:07 +00:00
|
|
|
import { connect } from '../../../base/redux/functions';
|
2022-06-08 07:44:47 +00:00
|
|
|
// @ts-ignore
|
2022-04-13 13:18:54 +00:00
|
|
|
import ToolboxButtonWithIconPopup from '../../../base/toolbox/components/web/ToolboxButtonWithIconPopup';
|
2021-07-13 06:50:08 +00:00
|
|
|
import { toggleReactionsMenuVisibility } from '../../actions.web';
|
2022-06-08 07:44:47 +00:00
|
|
|
import { ReactionEmojiProps } from '../../constants';
|
2021-09-21 17:30:24 +00:00
|
|
|
import { getReactionsQueue, isReactionsEnabled } from '../../functions.any';
|
2021-07-13 06:50:08 +00:00
|
|
|
import { getReactionsMenuVisibility } from '../../functions.web';
|
|
|
|
|
2022-06-08 07:44:47 +00:00
|
|
|
// @ts-ignore
|
2022-01-04 11:21:00 +00:00
|
|
|
import RaiseHandButton from './RaiseHandButton';
|
2021-07-13 06:50:08 +00:00
|
|
|
import ReactionEmoji from './ReactionEmoji';
|
2022-04-13 13:18:54 +00:00
|
|
|
import ReactionsMenu from './ReactionsMenu';
|
2021-07-13 06:50:08 +00:00
|
|
|
|
2022-08-08 09:36:06 +00:00
|
|
|
interface Props extends WithTranslation {
|
2021-07-13 06:50:08 +00:00
|
|
|
|
|
|
|
/**
|
2021-09-21 17:30:24 +00:00
|
|
|
* Whether or not reactions are enabled.
|
2021-07-13 06:50:08 +00:00
|
|
|
*/
|
2022-09-08 09:52:36 +00:00
|
|
|
_reactionsEnabled: Boolean;
|
2021-07-13 06:50:08 +00:00
|
|
|
|
2022-01-04 11:21:00 +00:00
|
|
|
/**
|
|
|
|
* The button's key.
|
|
|
|
*/
|
2022-09-08 09:52:36 +00:00
|
|
|
buttonKey?: string;
|
2022-01-04 11:21:00 +00:00
|
|
|
|
2021-07-13 06:50:08 +00:00
|
|
|
/**
|
2021-09-21 17:30:24 +00:00
|
|
|
* Redux dispatch function.
|
2021-07-13 06:50:08 +00:00
|
|
|
*/
|
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
|
|
|
* Click handler for raise hand functionality.
|
2021-07-13 06:50:08 +00:00
|
|
|
*/
|
2022-09-08 09:52:36 +00:00
|
|
|
handleClick: Function;
|
2021-07-13 06:50:08 +00:00
|
|
|
|
|
|
|
/**
|
2022-07-20 08:47:01 +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
|
|
|
|
2021-09-21 17:30:24 +00:00
|
|
|
/**
|
2022-07-20 08:47:01 +00:00
|
|
|
* Whether or not the reactions menu is open.
|
2021-09-21 17:30:24 +00:00
|
|
|
*/
|
2022-09-08 09:52:36 +00:00
|
|
|
isOpen: boolean;
|
2021-09-21 17:30:24 +00:00
|
|
|
|
|
|
|
/**
|
2022-01-04 11:21:00 +00:00
|
|
|
* Notify mode for `toolbarButtonClicked` event -
|
|
|
|
* whether to only notify or to also prevent button click routine.
|
2021-09-21 17:30:24 +00:00
|
|
|
*/
|
2022-09-08 09:52:36 +00:00
|
|
|
notifyMode?: string;
|
2021-09-21 17:30:24 +00:00
|
|
|
|
2021-07-13 06:50:08 +00:00
|
|
|
/**
|
|
|
|
* The array of reactions to be displayed.
|
|
|
|
*/
|
2022-09-08 09:52:36 +00:00
|
|
|
reactionsQueue: Array<ReactionEmojiProps>;
|
2022-08-08 09:36:06 +00:00
|
|
|
}
|
2021-07-13 06:50:08 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Button used for the reactions menu.
|
|
|
|
*
|
|
|
|
* @returns {ReactElement}
|
|
|
|
*/
|
|
|
|
function ReactionsMenuButton({
|
2021-09-21 17:30:24 +00:00
|
|
|
_reactionsEnabled,
|
2022-01-04 11:21:00 +00:00
|
|
|
buttonKey,
|
2021-09-21 17:30:24 +00:00
|
|
|
dispatch,
|
|
|
|
handleClick,
|
2021-07-13 06:50:08 +00:00
|
|
|
isOpen,
|
2021-09-21 17:30:24 +00:00
|
|
|
isMobile,
|
2022-01-04 11:21:00 +00:00
|
|
|
notifyMode,
|
2021-07-13 06:50:08 +00:00
|
|
|
reactionsQueue,
|
2021-09-21 17:30:24 +00:00
|
|
|
t
|
2021-07-13 06:50:08 +00:00
|
|
|
}: Props) {
|
2022-04-13 13:18:54 +00:00
|
|
|
const visible = useSelector(getReactionsMenuVisibility);
|
2021-11-04 21:10:43 +00:00
|
|
|
const toggleReactionsMenu = useCallback(() => {
|
2021-07-13 06:50:08 +00:00
|
|
|
dispatch(toggleReactionsMenuVisibility());
|
2021-11-04 21:10:43 +00:00
|
|
|
}, [ dispatch ]);
|
2021-07-13 06:50:08 +00:00
|
|
|
|
2022-04-13 13:18:54 +00:00
|
|
|
const openReactionsMenu = useCallback(() => {
|
|
|
|
!visible && toggleReactionsMenu();
|
|
|
|
}, [ visible, toggleReactionsMenu ]);
|
|
|
|
|
|
|
|
const reactionsMenu = (<div className = 'reactions-menu-container'>
|
|
|
|
<ReactionsMenu />
|
|
|
|
</div>);
|
|
|
|
|
2021-07-13 06:50:08 +00:00
|
|
|
return (
|
|
|
|
<div className = 'reactions-menu-popup-container'>
|
2022-04-13 13:18:54 +00:00
|
|
|
{!_reactionsEnabled || isMobile ? (
|
|
|
|
<RaiseHandButton
|
|
|
|
buttonKey = { buttonKey }
|
|
|
|
handleClick = { handleClick }
|
|
|
|
notifyMode = { notifyMode } />)
|
|
|
|
: (
|
|
|
|
<ToolboxButtonWithIconPopup
|
|
|
|
ariaControls = 'reactions-menu-dialog'
|
|
|
|
ariaExpanded = { isOpen }
|
|
|
|
ariaHasPopup = { true }
|
|
|
|
ariaLabel = { t('toolbar.accessibilityLabel.reactionsMenu') }
|
|
|
|
icon = { IconArrowUp }
|
|
|
|
iconDisabled = { false }
|
|
|
|
iconId = 'reactions-menu-button'
|
|
|
|
onPopoverClose = { toggleReactionsMenu }
|
|
|
|
onPopoverOpen = { openReactionsMenu }
|
|
|
|
popoverContent = { reactionsMenu }
|
|
|
|
visible = { visible }>
|
|
|
|
<RaiseHandButton
|
2022-01-04 11:21:00 +00:00
|
|
|
buttonKey = { buttonKey }
|
2022-04-13 13:18:54 +00:00
|
|
|
handleClick = { handleClick }
|
|
|
|
notifyMode = { notifyMode } />
|
|
|
|
</ToolboxButtonWithIconPopup>
|
|
|
|
)}
|
2021-07-13 06:50:08 +00:00
|
|
|
{reactionsQueue.map(({ reaction, uid }, index) => (<ReactionEmoji
|
|
|
|
index = { index }
|
|
|
|
key = { uid }
|
|
|
|
reaction = { reaction }
|
|
|
|
uid = { uid } />))}
|
|
|
|
</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
|
|
|
return {
|
2021-09-21 17:30:24 +00:00
|
|
|
_reactionsEnabled: isReactionsEnabled(state),
|
2021-07-13 06:50:08 +00:00
|
|
|
isOpen: getReactionsMenuVisibility(state),
|
2021-09-21 17:30:24 +00:00
|
|
|
isMobile: isMobileBrowser(),
|
2022-01-04 11:21:00 +00:00
|
|
|
reactionsQueue: getReactionsQueue(state)
|
2021-07-13 06:50:08 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
export default translate(connect(mapStateToProps)(ReactionsMenuButton));
|