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

197 lines
5.3 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';
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';
import { Emoji } from 'emoji-mart';
2023-08-31 02:59:05 +08:00
import { convertRemToPixels } from '/imports/utils/dom-utils';
2023-04-28 05:31:11 +08:00
import Styled from './styles';
2023-07-18 19:54:36 +08:00
const ReactionsButton = (props) => {
const {
intl,
actionsBarRef,
2023-06-27 20:50:04 +08:00
userId,
raiseHand,
2023-06-27 22:08:49 +08:00
isMobile,
2023-07-19 22:36:34 +08:00
currentUserReaction,
2023-08-11 03:28:21 +08:00
autoCloseReactionsBar,
} = props;
const [showEmojiPicker, setShowEmojiPicker] = useState(false);
const intlMessages = defineMessages({
2023-07-18 19:54:36 +08:00
reactionsLabel: {
id: 'app.actionsBar.reactions.reactionsButtonLabel',
description: 'reactions Label',
},
raiseHandLabel: {
id: 'app.actionsBar.reactions.raiseHand',
description: 'raise Hand Label',
},
notRaiseHandLabel: {
id: 'app.actionsBar.reactions.lowHand',
description: 'not Raise Hand 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) => {
2023-07-19 22:36:34 +08:00
const newReaction = currentUserReaction === reaction ? 'none' : reaction;
UserReactionService.setUserReaction(newReaction);
2023-06-27 20:50:04 +08:00
};
const handleRaiseHandButtonClick = () => {
UserListService.setUserRaiseHand(userId, !raiseHand);
};
const RaiseHandButtonLabel = () => {
if (isMobile) return null;
return raiseHand
? intl.formatMessage(intlMessages.notRaiseHandLabel)
: intl.formatMessage(intlMessages.raiseHandLabel);
};
const customStyles = {
top: '-1rem',
borderRadius: '1.7rem',
};
const actionCustomStyles = {
paddingLeft: 0,
paddingRight: 0,
paddingTop: isMobile ? '0' : '0.5rem',
paddingBottom: isMobile ? '0' : '0.5rem',
};
const emojiProps = {
native: true,
2023-08-31 02:59:05 +08:00
size: convertRemToPixels(1.5),
2023-08-09 02:28:05 +08:00
padding: '4px',
};
const reactions = [
{
id: 'smiley',
native: '😃',
},
{
id: 'neutral_face',
native: '😐',
},
{
id: 'slightly_frowning_face',
native: '🙁',
},
{
id: '+1',
native: '👍',
},
{
id: '-1',
native: '👎',
},
{
id: 'clap',
native: '👏',
},
];
let actions = [];
reactions.forEach(({ id, native }) => {
actions.push({
label: <Styled.ButtonWrapper active={currentUserReaction === native}><Emoji key={id} emoji={{ id }} {...emojiProps} /></Styled.ButtonWrapper>,
key: id,
onClick: () => handleReactionSelect(native),
customStyles: actionCustomStyles,
});
});
actions.push({
label: <Styled.RaiseHandButtonWrapper isMobile={isMobile} data-test={raiseHand ? 'lowerHandBtn' : 'raiseHandBtn'} active={raiseHand}><Emoji key="hand" emoji={{ id: 'hand' }} {...emojiProps} />{RaiseHandButtonLabel()}</Styled.RaiseHandButtonWrapper>,
key: 'hand',
onClick: () => handleRaiseHandButtonClick(),
customStyles: {...actionCustomStyles, width: 'auto'},
});
const icon = !raiseHand && currentUserReaction === 'none' ? 'hand' : null;
const currentUserReactionEmoji = reactions.find(({ native }) => native === currentUserReaction);
let customIcon = null;
if (raiseHand) {
customIcon = <Emoji key="hand" emoji={{ id: 'hand' }} {...emojiProps} />;
} else {
if (!icon) {
customIcon = <Emoji key={currentUserReactionEmoji?.id} emoji={{ id: currentUserReactionEmoji?.id }} {...emojiProps} />;
}
}
return (
<BBBMenu
trigger={(
2023-09-19 06:02:21 +08:00
<Styled.ReactionsDropdown id="interactionsButton">
<Styled.RaiseHandButton
data-test="reactionsButton"
icon={icon}
customIcon={customIcon}
2023-07-18 19:54:36 +08:00
label={intl.formatMessage(intlMessages.reactionsLabel)}
description="Reactions"
ghost={!showEmojiPicker && !customIcon}
onKeyPress={() => {}}
2023-06-14 01:51:42 +08:00
onClick={() => setShowEmojiPicker(true)}
color={showEmojiPicker || customIcon ? 'primary' : 'default'}
hideLabel
circle
size="lg"
/>
2023-07-18 19:54:36 +08:00
</Styled.ReactionsDropdown>
)}
actions={actions}
onCloseCallback={() => handleClose()}
2023-06-27 22:08:49 +08:00
customAnchorEl={!isMobile ? actionsBarRef.current : null}
2023-06-14 01:51:42 +08:00
customStyles={customStyles}
2023-06-27 20:50:04 +08:00
open={showEmojiPicker}
2023-06-15 03:35:44 +08:00
hasRoundedCorners
2023-06-27 22:08:49 +08:00
overrideMobileStyles
isHorizontal={!isMobile}
isMobile={isMobile}
2023-08-05 03:14:57 +08:00
roundButtons={true}
2023-08-11 03:28:21 +08:00
keepOpen={!autoCloseReactionsBar}
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,
};
2023-07-18 19:54:36 +08:00
ReactionsButton.propTypes = propTypes;
2023-07-18 19:54:36 +08:00
export default ReactionsButton;