2023-06-14 01:51:42 +08:00
|
|
|
import React, { useState } from 'react';
|
2021-10-14 22:11:37 +08:00
|
|
|
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';
|
2021-10-14 22:11:37 +08:00
|
|
|
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';
|
2021-10-14 22:11:37 +08:00
|
|
|
|
2023-07-18 19:54:36 +08:00
|
|
|
const ReactionsButton = (props) => {
|
2021-10-14 22:11:37 +08:00
|
|
|
const {
|
|
|
|
intl,
|
2023-06-23 20:32:55 +08:00
|
|
|
actionsBarRef,
|
2023-06-27 20:50:04 +08:00
|
|
|
userId,
|
|
|
|
raiseHand,
|
2023-06-27 22:08:49 +08:00
|
|
|
isMobile,
|
2021-10-14 22:11:37 +08:00
|
|
|
} = 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',
|
2021-10-14 22:11:37 +08:00
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
const handleClose = () => {
|
|
|
|
setShowEmojiPicker(false);
|
2023-06-27 20:50:04 +08:00
|
|
|
setTimeout(() => {
|
|
|
|
document.activeElement.blur();
|
|
|
|
}, 0);
|
2021-10-14 22:11:37 +08:00
|
|
|
};
|
|
|
|
|
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();
|
2021-10-14 22:11:37 +08:00
|
|
|
};
|
|
|
|
|
2023-06-14 01:51:42 +08:00
|
|
|
const renderReactionsBar = () => (
|
2022-09-07 00:18:08 +08:00
|
|
|
<Styled.Wrapper>
|
2023-06-27 20:50:04 +08:00
|
|
|
<ReactionsBar {...props} onReactionSelect={handleReactionSelect} onRaiseHand={handleRaiseHandButtonClick} />
|
2022-09-07 00:18:08 +08:00
|
|
|
</Styled.Wrapper>
|
2021-10-14 22:11:37 +08:00
|
|
|
);
|
|
|
|
|
2023-06-14 01:51:42 +08:00
|
|
|
const customStyles = { top: '-1rem', borderRadius: '1.7rem' };
|
2021-10-14 22:11:37 +08:00
|
|
|
|
|
|
|
return (
|
|
|
|
<BBBMenu
|
|
|
|
trigger={(
|
2023-07-18 19:54:36 +08:00
|
|
|
<Styled.ReactionsDropdown>
|
2022-09-07 00:34:43 +08:00
|
|
|
<Styled.RaiseHandButton
|
2023-07-18 19:54:36 +08:00
|
|
|
data-test="ReactionsButton"
|
2023-06-08 02:49:40 +08:00
|
|
|
icon="hand"
|
2023-07-18 19:54:36 +08:00
|
|
|
label={intl.formatMessage(intlMessages.reactionsLabel)}
|
|
|
|
description="Reactions"
|
2023-06-14 01:51:42 +08:00
|
|
|
ghost={!showEmojiPicker}
|
2021-10-14 22:11:37 +08:00
|
|
|
onKeyPress={() => {}}
|
2023-06-14 01:51:42 +08:00
|
|
|
onClick={() => setShowEmojiPicker(true)}
|
|
|
|
color={showEmojiPicker ? 'primary' : 'default'}
|
2021-10-14 22:11:37 +08:00
|
|
|
hideLabel
|
|
|
|
circle
|
|
|
|
size="lg"
|
|
|
|
/>
|
2023-07-18 19:54:36 +08:00
|
|
|
</Styled.ReactionsDropdown>
|
2021-10-14 22:11:37 +08:00
|
|
|
)}
|
2023-06-15 03:35:44 +08:00
|
|
|
renderOtherComponents={showEmojiPicker ? renderReactionsBar() : null}
|
2021-10-14 22:11:37 +08:00
|
|
|
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
|
2021-10-14 22:11:37 +08:00
|
|
|
opts={{
|
2023-06-14 01:51:42 +08:00
|
|
|
id: 'reactions-dropdown-menu',
|
2022-09-27 02:38:45 +08:00
|
|
|
keepMounted: true,
|
2021-10-14 22:11:37 +08:00
|
|
|
transitionDuration: 0,
|
|
|
|
elevation: 3,
|
2022-09-27 02:38:45 +08:00
|
|
|
getContentAnchorEl: null,
|
2023-06-14 01:51:42 +08:00
|
|
|
anchorOrigin: { vertical: 'top', horizontal: 'center' },
|
|
|
|
transformOrigin: { vertical: 'bottom', horizontal: 'center' },
|
2021-10-14 22:11:37 +08:00
|
|
|
}}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
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;
|
2021-10-14 22:11:37 +08:00
|
|
|
|
2023-07-18 19:54:36 +08:00
|
|
|
export default ReactionsButton;
|