2022-08-25 11:35:19 +00:00
|
|
|
/* eslint-disable lines-around-comment */
|
2022-10-19 08:43:10 +00:00
|
|
|
import React, { ReactNode, useCallback } from 'react';
|
|
|
|
import { useSelector } from 'react-redux';
|
|
|
|
import { makeStyles } from 'tss-react/mui';
|
2018-03-07 00:28:19 +00:00
|
|
|
|
2022-09-07 08:20:05 +00:00
|
|
|
import { createToolbarEvent } from '../../../analytics/AnalyticsEvents';
|
|
|
|
import { sendAnalytics } from '../../../analytics/functions';
|
2022-10-20 09:11:27 +00:00
|
|
|
import { IReduxState } from '../../../app/types';
|
2022-10-24 09:51:18 +00:00
|
|
|
import Popover from '../../../base/popover/components/Popover.web';
|
2022-08-25 11:35:19 +00:00
|
|
|
// @ts-ignore
|
2021-07-13 06:50:08 +00:00
|
|
|
import { ReactionEmoji, ReactionsMenu } from '../../../reactions/components';
|
2022-10-19 08:43:10 +00:00
|
|
|
import { REACTIONS_MENU_HEIGHT } from '../../../reactions/constants';
|
2021-07-13 06:50:08 +00:00
|
|
|
import { getReactionsQueue } from '../../../reactions/functions.any';
|
2022-04-05 12:19:03 +00:00
|
|
|
import { DRAWER_MAX_HEIGHT } from '../../constants';
|
2018-03-07 00:28:19 +00:00
|
|
|
|
2022-08-25 11:35:19 +00:00
|
|
|
// @ts-ignore
|
2021-01-04 13:30:23 +00:00
|
|
|
import Drawer from './Drawer';
|
2022-08-25 11:35:19 +00:00
|
|
|
// @ts-ignore
|
2021-10-04 14:07:05 +00:00
|
|
|
import JitsiPortal from './JitsiPortal';
|
2022-08-25 11:35:19 +00:00
|
|
|
// @ts-ignore
|
2022-01-04 11:21:00 +00:00
|
|
|
import OverflowToggleButton from './OverflowToggleButton';
|
2018-03-07 00:28:19 +00:00
|
|
|
|
|
|
|
/**
|
2018-10-30 05:02:23 +00:00
|
|
|
* The type of the React {@code Component} props of {@link OverflowMenuButton}.
|
2018-03-07 00:28:19 +00:00
|
|
|
*/
|
2022-10-20 09:11:27 +00:00
|
|
|
interface IProps {
|
2018-10-30 05:02:23 +00:00
|
|
|
|
2021-06-10 12:48:44 +00:00
|
|
|
/**
|
|
|
|
* ID of the menu that is controlled by this button.
|
|
|
|
*/
|
2022-10-19 08:43:10 +00:00
|
|
|
ariaControls: string;
|
2021-06-10 12:48:44 +00:00
|
|
|
|
2018-03-07 00:28:19 +00:00
|
|
|
/**
|
2022-10-25 13:11:55 +00:00
|
|
|
* A child React Element to display within {@code Popover}.
|
2018-10-30 05:02:23 +00:00
|
|
|
*/
|
2022-10-19 08:43:10 +00:00
|
|
|
children: ReactNode;
|
2022-04-05 12:19:03 +00:00
|
|
|
|
2018-10-30 05:02:23 +00:00
|
|
|
/**
|
|
|
|
* Whether or not the OverflowMenu popover should display.
|
|
|
|
*/
|
2022-09-08 09:52:36 +00:00
|
|
|
isOpen: boolean;
|
2018-10-30 05:02:23 +00:00
|
|
|
|
|
|
|
/**
|
2021-03-16 15:59:33 +00:00
|
|
|
* Callback to change the visibility of the overflow menu.
|
2018-03-07 00:28:19 +00:00
|
|
|
*/
|
2022-09-08 09:52:36 +00:00
|
|
|
onVisibilityChange: Function;
|
2018-03-07 00:28:19 +00:00
|
|
|
|
2021-07-13 06:50:08 +00:00
|
|
|
/**
|
|
|
|
* Whether or not to display the reactions in the mobile menu.
|
|
|
|
*/
|
2022-09-08 09:52:36 +00:00
|
|
|
showMobileReactions: boolean;
|
2022-08-25 11:35:19 +00:00
|
|
|
}
|
2018-10-30 05:02:23 +00:00
|
|
|
|
2022-10-19 08:43:10 +00:00
|
|
|
const useStyles = makeStyles()(() => {
|
2022-04-05 12:19:03 +00:00
|
|
|
return {
|
|
|
|
overflowMenuDrawer: {
|
2022-09-13 07:36:00 +00:00
|
|
|
overflowY: 'auto' as const,
|
2022-04-05 12:19:03 +00:00
|
|
|
height: `calc(${DRAWER_MAX_HEIGHT} - ${REACTIONS_MENU_HEIGHT}px - 16px)`
|
|
|
|
}
|
|
|
|
};
|
2022-10-19 08:43:10 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
const OverflowMenuButton = ({
|
|
|
|
children,
|
|
|
|
isOpen,
|
|
|
|
onVisibilityChange,
|
|
|
|
showMobileReactions
|
2022-10-20 09:11:27 +00:00
|
|
|
}: IProps) => {
|
2022-10-19 08:43:10 +00:00
|
|
|
const { classes } = useStyles();
|
2022-10-20 09:11:27 +00:00
|
|
|
const overflowDrawer = useSelector((state: IReduxState) => state['features/toolbox'].overflowDrawer);
|
2022-10-19 08:43:10 +00:00
|
|
|
const reactionsQueue = useSelector(getReactionsQueue);
|
|
|
|
|
|
|
|
const onCloseDialog = useCallback(() => {
|
|
|
|
onVisibilityChange(false);
|
|
|
|
}, [ onVisibilityChange ]);
|
|
|
|
|
2022-10-24 09:51:18 +00:00
|
|
|
const onOpenDialog = useCallback(() => {
|
|
|
|
onVisibilityChange(true);
|
|
|
|
}, [ onVisibilityChange ]);
|
|
|
|
|
2022-10-19 08:43:10 +00:00
|
|
|
const onEscClick = useCallback((event: React.KeyboardEvent) => {
|
|
|
|
if (event.key === 'Escape' && isOpen) {
|
2021-06-10 12:48:44 +00:00
|
|
|
event.preventDefault();
|
|
|
|
event.stopPropagation();
|
2022-10-19 08:43:10 +00:00
|
|
|
onCloseDialog();
|
2021-06-10 12:48:44 +00:00
|
|
|
}
|
2022-10-19 08:43:10 +00:00
|
|
|
}, [ onCloseDialog ]);
|
2018-03-07 00:28:19 +00:00
|
|
|
|
2022-10-19 08:43:10 +00:00
|
|
|
const toggleDialogVisibility = useCallback(() => {
|
2018-04-20 11:24:14 +00:00
|
|
|
sendAnalytics(createToolbarEvent('overflow'));
|
|
|
|
|
2022-10-19 08:43:10 +00:00
|
|
|
onVisibilityChange(!isOpen);
|
|
|
|
}, [ isOpen, onVisibilityChange ]);
|
2021-01-04 13:30:23 +00:00
|
|
|
|
2022-10-19 08:43:10 +00:00
|
|
|
return (
|
|
|
|
<div className = 'toolbox-button-wth-dialog context-menu'>
|
|
|
|
{
|
|
|
|
overflowDrawer ? (
|
|
|
|
<>
|
|
|
|
<OverflowToggleButton
|
|
|
|
handleClick = { toggleDialogVisibility }
|
|
|
|
isOpen = { isOpen }
|
|
|
|
onKeyDown = { onEscClick } />
|
|
|
|
<JitsiPortal>
|
|
|
|
<Drawer
|
|
|
|
isOpen = { isOpen }
|
|
|
|
onClose = { onCloseDialog }>
|
|
|
|
<>
|
|
|
|
<div className = { classes.overflowMenuDrawer }>
|
|
|
|
{children}
|
|
|
|
</div>
|
|
|
|
{showMobileReactions && <ReactionsMenu overflowMenu = { true } />}
|
|
|
|
</>
|
|
|
|
</Drawer>
|
|
|
|
{showMobileReactions && <div className = 'reactions-animations-container'>
|
|
|
|
{reactionsQueue.map(({ reaction, uid }, index) => (<ReactionEmoji
|
|
|
|
index = { index }
|
|
|
|
key = { uid }
|
|
|
|
reaction = { reaction }
|
|
|
|
uid = { uid } />))}
|
|
|
|
</div>}
|
|
|
|
</JitsiPortal>
|
|
|
|
</>
|
|
|
|
) : (
|
2022-10-24 09:51:18 +00:00
|
|
|
<Popover
|
2022-10-19 08:43:10 +00:00
|
|
|
content = { children }
|
2022-10-24 09:51:18 +00:00
|
|
|
onPopoverClose = { onCloseDialog }
|
|
|
|
onPopoverOpen = { onOpenDialog }
|
|
|
|
position = 'top'
|
|
|
|
trigger = 'click'
|
|
|
|
visible = { isOpen }>
|
2022-10-19 08:43:10 +00:00
|
|
|
<OverflowToggleButton
|
|
|
|
isOpen = { isOpen }
|
|
|
|
onKeyDown = { onEscClick } />
|
2022-10-24 09:51:18 +00:00
|
|
|
</Popover>
|
2022-10-19 08:43:10 +00:00
|
|
|
)
|
|
|
|
}
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
};
|
2021-01-04 13:30:23 +00:00
|
|
|
|
2022-10-19 08:43:10 +00:00
|
|
|
export default OverflowMenuButton;
|