bigbluebutton-Github/bigbluebutton-html5/imports/ui/components/actions-bar/interactions-button/component.jsx

104 lines
3.0 KiB
React
Raw Normal View History

2023-06-14 01:51:42 +08:00
import React, { useState } from 'react';
import { defineMessages } from 'react-intl';
import PropTypes from 'prop-types';
2023-04-28 05:31:11 +08:00
import BBBMenu from '/imports/ui/components/common/menu/component';
2023-06-14 01:51:42 +08:00
import ReactionsBar from '/imports/ui/components/emoji-picker/reactions-bar/component';
import UserReactionService from '/imports/ui/components/user-reaction/service';
2023-06-27 20:50:04 +08:00
import UserListService from '/imports/ui/components/user-list/service';
2023-04-28 05:31:11 +08:00
import Styled from '../styles';
const InteractionsButton = (props) => {
const {
intl,
actionsBarRef,
2023-06-27 20:50:04 +08:00
userId,
raiseHand,
} = props;
const [showEmojiPicker, setShowEmojiPicker] = useState(false);
const intlMessages = defineMessages({
interactionsLabel: {
id: 'app.actionsBar.interactions.interactions',
description: 'interactions Label',
},
});
const handleClose = () => {
setShowEmojiPicker(false);
2023-06-27 20:50:04 +08:00
setTimeout(() => {
document.activeElement.blur();
}, 0);
};
2023-06-14 01:51:42 +08:00
const handleReactionSelect = (reaction) => {
UserReactionService.setUserReaction(reaction);
2023-06-27 20:50:04 +08:00
handleClose();
};
const handleRaiseHandButtonClick = () => {
UserListService.setUserRaiseHand(userId, !raiseHand);
handleClose();
};
2023-06-14 01:51:42 +08:00
const renderReactionsBar = () => (
<Styled.Wrapper>
2023-06-27 20:50:04 +08:00
<ReactionsBar {...props} onReactionSelect={handleReactionSelect} onRaiseHand={handleRaiseHandButtonClick} />
</Styled.Wrapper>
);
2023-06-14 01:51:42 +08:00
const customStyles = { top: '-1rem', borderRadius: '1.7rem' };
return (
<BBBMenu
trigger={(
<Styled.InteractionsDropdown>
<Styled.RaiseHandButton
data-test="InteractionsButton"
icon="hand"
2023-06-14 01:51:42 +08:00
label={intl.formatMessage(intlMessages.interactionsLabel)}
description="Interactions"
2023-06-14 01:51:42 +08:00
ghost={!showEmojiPicker}
onKeyPress={() => {}}
2023-06-14 01:51:42 +08:00
onClick={() => setShowEmojiPicker(true)}
color={showEmojiPicker ? 'primary' : 'default'}
hideLabel
circle
size="lg"
/>
2023-04-28 05:31:11 +08:00
</Styled.InteractionsDropdown>
)}
2023-06-15 03:35:44 +08:00
renderOtherComponents={showEmojiPicker ? renderReactionsBar() : null}
onCloseCallback={() => handleClose()}
2023-06-14 01:51:42 +08:00
customAnchorEl={actionsBarRef.current}
customStyles={customStyles}
2023-06-27 20:50:04 +08:00
open={showEmojiPicker}
2023-06-15 03:35:44 +08:00
hasRoundedCorners
opts={{
2023-06-14 01:51:42 +08:00
id: 'reactions-dropdown-menu',
keepMounted: true,
transitionDuration: 0,
elevation: 3,
getContentAnchorEl: null,
2023-06-14 01:51:42 +08:00
anchorOrigin: { vertical: 'top', horizontal: 'center' },
transformOrigin: { vertical: 'bottom', horizontal: 'center' },
}}
/>
);
};
const propTypes = {
intl: PropTypes.shape({
formatMessage: PropTypes.func.isRequired,
}).isRequired,
userId: PropTypes.string.isRequired,
emoji: PropTypes.string.isRequired,
sidebarContentPanel: PropTypes.string.isRequired,
layoutContextDispatch: PropTypes.func.isRequired,
};
InteractionsButton.propTypes = propTypes;
export default InteractionsButton;