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

215 lines
6.1 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-08-31 02:59:05 +08:00
import { convertRemToPixels } from '/imports/utils/dom-utils';
import data from '@emoji-mart/data';
import { init } from 'emoji-mart';
import { SET_REACTION_EMOJI } from '/imports/ui/core/graphql/mutations/userMutations';
2024-04-24 01:56:23 +08:00
import { SET_AWAY } from '/imports/ui/components/user-list/user-list-content/user-participants/user-list-participants/user-actions/mutations';
2023-12-07 03:30:30 +08:00
import { useMutation } from '@apollo/client';
2024-04-24 01:56:23 +08:00
import Toggle from '/imports/ui/components/common/switch/component';
import useToggleVoice from '/imports/ui/components/audio/audio-graphql/hooks/useToggleVoice';
import {
muteAway,
2024-04-24 01:56:23 +08:00
} from '/imports/ui/components/audio/audio-graphql/audio-controls/input-stream-live-selector/service';
import Styled from './styles';
2023-07-18 19:54:36 +08:00
const ReactionsButton = (props) => {
const {
intl,
actionsBarRef,
2024-04-24 01:56:23 +08:00
away,
muted,
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 REACTIONS = window.meetingClientSettings.public.userReaction.reactions;
// initialize emoji-mart data, need for the new version
init({ data });
2024-04-24 01:56:23 +08:00
const [setAway] = useMutation(SET_AWAY);
2023-12-07 21:57:21 +08:00
const [setReactionEmoji] = useMutation(SET_REACTION_EMOJI);
2023-12-07 03:30:30 +08:00
const [showEmojiPicker, setShowEmojiPicker] = useState(false);
2024-04-24 01:56:23 +08:00
const voiceToggle = useToggleVoice();
const intlMessages = defineMessages({
2023-07-18 19:54:36 +08:00
reactionsLabel: {
id: 'app.actionsBar.reactions.reactionsButtonLabel',
description: 'reactions Label',
},
2024-04-24 01:56:23 +08:00
setAwayLabel: {
id: 'app.actionsBar.reactions.setAway',
description: 'setAway Label',
},
setActiveLabel: {
id: 'app.actionsBar.reactions.setActive',
description: 'setActive 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) => {
2024-08-17 00:31:25 +08:00
setReactionEmoji({ variables: { reactionEmoji: reaction } });
2023-06-27 20:50:04 +08:00
};
2024-04-24 01:56:23 +08:00
const handleToggleAFK = () => {
muteAway(muted, away, voiceToggle);
2024-04-24 01:56:23 +08:00
setAway({
variables: {
away: !away,
},
});
};
const ToggleAFKLabel = () => (away
? intl.formatMessage(intlMessages.setActiveLabel)
: intl.formatMessage(intlMessages.setAwayLabel));
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 = {
2023-08-31 02:59:05 +08:00
size: convertRemToPixels(1.5),
2023-08-09 02:28:05 +08:00
padding: '4px',
};
2024-04-24 01:56:23 +08:00
const awayReaction = {
id: 'clock7',
native: '⏰',
};
let actions = [];
REACTIONS.forEach(({ id, native }) => {
actions.push({
label: <Styled.ButtonWrapper active={currentUserReaction === native}><em-emoji key={native} native={native} {...emojiProps} /></Styled.ButtonWrapper>,
key: id,
onClick: () => handleReactionSelect(native),
customStyles: actionCustomStyles,
});
});
2024-04-24 01:56:23 +08:00
actions.push({
label: <Styled.ToggleButtonWrapper isMobile={isMobile}>
{isMobile ? (
<div style={{ display: 'flex', flexDirection: 'column' }}>
{ToggleAFKLabel()}
<Toggle
icons={false}
checked={away}
onChange={handleToggleAFK}
ariaLabel={ToggleAFKLabel()}
showToggleLabel={false}
isMobile={isMobile}
/>
</div>
) : (
<>
<Toggle
icons={false}
checked={away}
onChange={handleToggleAFK}
ariaLabel={ToggleAFKLabel()}
showToggleLabel={false}
/>
{ToggleAFKLabel()}
</>
)}
</Styled.ToggleButtonWrapper>,
2024-04-24 01:56:23 +08:00
key: 'none',
isToggle: true,
customStyles: { ...actionCustomStyles, width: 'auto' },
2024-04-24 01:56:23 +08:00
});
const svgIcon = !away && currentUserReaction === 'none' ? 'reactions' : null;
const currentUserReactionEmoji = REACTIONS.find(({ native }) => native === currentUserReaction);
let customIcon = null;
if (!svgIcon) {
customIcon = <em-emoji key={currentUserReactionEmoji?.id} native={currentUserReactionEmoji?.native} emoji={{ id: currentUserReactionEmoji?.id }} {...emojiProps} />;
}
2024-04-24 01:56:23 +08:00
if (away) {
customIcon = <em-emoji key={awayReaction.id} native={awayReaction.native} emoji={awayReaction} {...emojiProps} />;
}
return (
<BBBMenu
trigger={(
<Styled.ReactionsDropdown id="interactionsButton">
<Styled.ReactionsButton
data-test="reactionsButton"
svgIcon={svgIcon}
customIcon={customIcon}
2023-07-18 19:54:36 +08:00
label={intl.formatMessage(intlMessages.reactionsLabel)}
description="Reactions"
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}
isEmoji
roundButtons
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,
sidebarContentPanel: PropTypes.string.isRequired,
layoutContextDispatch: PropTypes.func.isRequired,
2024-04-24 01:56:23 +08:00
muted: PropTypes.bool.isRequired,
};
2023-07-18 19:54:36 +08:00
ReactionsButton.propTypes = propTypes;
export default ReactionsButton;