您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

PrivateMessageButton.tsx 2.2KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. import React, { useCallback } from 'react';
  2. import { useTranslation } from 'react-i18next';
  3. import { useDispatch, useSelector } from 'react-redux';
  4. import { makeStyles } from 'tss-react/mui';
  5. import { IReduxState } from '../../../app/types';
  6. import { CHAT_ENABLED } from '../../../base/flags/constants';
  7. import { getFeatureFlag } from '../../../base/flags/functions';
  8. import { IconReply } from '../../../base/icons/svg';
  9. import { getParticipantById } from '../../../base/participants/functions';
  10. import Button from '../../../base/ui/components/web/Button';
  11. import { BUTTON_TYPES } from '../../../base/ui/constants.any';
  12. import { handleLobbyChatInitialized, openChat } from '../../actions.web';
  13. export interface IProps {
  14. /**
  15. * True if the message is a lobby chat message.
  16. */
  17. isLobbyMessage: boolean;
  18. /**
  19. * The ID of the participant that the message is to be sent.
  20. */
  21. participantID: string;
  22. /**
  23. * Whether the button should be visible or not.
  24. */
  25. visible?: boolean;
  26. }
  27. const useStyles = makeStyles()(theme => {
  28. return {
  29. replyButton: {
  30. padding: '2px',
  31. '&:hover': {
  32. backgroundColor: theme.palette.action03
  33. }
  34. }
  35. };
  36. });
  37. const PrivateMessageButton = ({ participantID, isLobbyMessage, visible }: IProps) => {
  38. const { classes } = useStyles();
  39. const dispatch = useDispatch();
  40. const participant = useSelector((state: IReduxState) => getParticipantById(state, participantID));
  41. const isVisible = useSelector((state: IReduxState) => getFeatureFlag(state, CHAT_ENABLED, true)) ?? visible;
  42. const { t } = useTranslation();
  43. const handleClick = useCallback(() => {
  44. if (isLobbyMessage) {
  45. dispatch(handleLobbyChatInitialized(participantID));
  46. } else {
  47. dispatch(openChat(participant));
  48. }
  49. }, []);
  50. if (!isVisible) {
  51. return null;
  52. }
  53. return (
  54. <Button
  55. accessibilityLabel = { t('toolbar.accessibilityLabel.privateMessage') }
  56. className = { classes.replyButton }
  57. icon = { IconReply }
  58. onClick = { handleClick }
  59. type = { BUTTON_TYPES.TERTIARY } />
  60. );
  61. };
  62. export default PrivateMessageButton;